Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There actually is an elegant solution, using <code>CheckBox</code> and single <code>TextView</code>. Along with a combinations of <code>TextView.setClickable()</code>, Intent Filter, and <code>TextView.setMovementMethod()</code>.</p> <p>You have main view (here, I called it <strong>ClickableTextViewExample</strong>):</p> <pre><code>package id.web.freelancer.example; import android.app.Activity; import android.os.Bundle; import android.text.Html; import android.text.method.LinkMovementMethod; import android.widget.CheckBox; import android.widget.TextView; public class ClickableTextViewExampleActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); CheckBox checkbox = (CheckBox)findViewById(R.id.checkBox1); TextView textView = (TextView)findViewById(R.id.textView2); checkbox.setText(""); textView.setText(Html.fromHtml("I have read and agree to the " + "&lt;a href='id.web.freelancer.example.TCActivity://Kode'&gt;TERMS AND CONDITIONS&lt;/a&gt;")); textView.setClickable(true); textView.setMovementMethod(LinkMovementMethod.getInstance()); } } </code></pre> <p><strong>main.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;CheckBox android:id="@+id/checkBox1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="CheckBox" /&gt; &lt;TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" android:clickable="true" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p><strong>TCActivity.java</strong></p> <pre><code>package id.web.freelancer.example; import android.app.Activity; import android.os.Bundle; public class TCActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tc); } } </code></pre> <p><strong>tc.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;TextView android:id="@+id/tcView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Terms and conditions" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>and the final piece of codes that glue it all, the <em>AndroidManifest.xml</em>:</p> <pre><code>&lt;activity android:name="TCActivity"&gt; &lt;intent-filter&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;action android:name="android.intent.action.VIEW" /&gt; &lt;data android:scheme="id.web.freelancer.example.TCActivity" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; </code></pre> <p>Here comes, the explanations:</p> <pre><code>textView.setText(Html.fromHtml("I have read and agree to the " + "&lt;a href='id.web.freelancer.example.TCActivity://Kode'&gt;TERMS AND CONDITIONS&lt;/a&gt;")); textView.setClickable(true); textView.setMovementMethod(LinkMovementMethod.getInstance()); </code></pre> <blockquote> <p><code>setClickable</code> will allow you to click on <code>textView</code>. But not the HREF link. To do that, you will have to use <code>setMovementMethod()</code> and set it to <code>LinkMovementMethod</code>.</p> </blockquote> <p>After that, you need to catch the URL. I did this using <code>intent-filter</code> in <strong>AndroidManifest.xml</strong></p> <pre><code>&lt;action android:name="android.intent.action.VIEW" /&gt; &lt;data android:scheme="id.web.freelancer.example.TCActivity" /&gt; </code></pre> <blockquote> <p>It catch VIEW command and it only filter URL starting with <code>id.web.freelancer.example.TCActivity://</code></p> </blockquote> <p><a href="http://dl.dropbox.com/u/1636195/gambar_stackoverflow_jangan_delete/ClickableTextViewExample.zip" rel="noreferrer">Here's the package for you to try it out</a> and <a href="https://github.com/ariefbayu/Clickable-URL-TextView-Example" rel="noreferrer">here's the github repository</a>. Hope this helped </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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