Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Display a pop-up dialog when a particular word in a TextView is clicked
    text
    copied!<p>In my application, I have some text for terms and conditions.</p> <blockquote> <p>By registering you agree to be bound by our Terms of Use and that you have read our Privacy Policy.</p> </blockquote> <p>The words <em>Terms of Use</em> and <em>Privacy Policy</em> should be clickable, and display an alert box.</p> <p>First I tried splitting the sentences into four <code>TextView</code>s:</p> <ol> <li>By registering you agree to be bound by our </li> <li>Terms of Use</li> <li>and that you have read our</li> <li>Privacy Policy.</li> </ol> <p>This worked well, with the following layout XML:</p> <pre><code> &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/termsandcondtion" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:orientation="horizontal" &gt; &lt;TextView android:id="@+id/terms_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/terms_1" android:textColor="#000000" android:textSize="12dp" /&gt; &lt;TextView android:id="@+id/terms" android:layout_width="wrap_content" android:layout_height="wrap_content" android:clickable="true" android:onClick="showTerms" android:text="@string/terms_2" android:textColor="#000000" android:textSize="12dp" /&gt; &lt;TextView android:id="@+id/terms_3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/terms_3" android:textColor="#000000" android:textSize="12dp" /&gt; &lt;TextView android:id="@+id/termsofuse" android:layout_width="wrap_content" android:layout_height="wrap_content" android:clickable="true" android:onClick="showTermsofUse" android:text="@string/terms_4" android:textColor="#000000" android:textSize="12dp" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>The code for displaying the popup is:</p> <pre><code>WebView wv = new WebView(this); wv.loadUrl(url); wv.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Privacy Policy"); alert.setView(wv); alert.setNegativeButton("Close", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }); alert.show(); </code></pre> <p>The problem is that the four <code>TextView</code>s are not properly aligned with each other. This means I have to use one <code>TextView</code> and display a pop-up diaplog when a particular word (Terms of Use, Privacy Policy) in <code>TextView</code> is clicked.</p> <p>What is the best way to do this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload