Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Hyperlink is not clickable

I have a few links in my application. One for a website, one for a phone number, and one for an email. The email and phone links are both working and clickable, however the website hyperlink is still not clickable for some reason. Any thoughts? Code below.

<string name="website" ><a href="http://www.XXXXXX.com">XXXXXX Website</a></string>
<string name="email" >[email protected]</string>
<string name="phone" >P: XXX.XXX.XXXX</string>
<string name="fax" >F: XXX.XXX.XXXX</string>

Above are my strings, and below is the xml file that displays them:

<TextView android:id="@+id/website"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_below="@id/imageButtonTwitter"
          android:gravity="center_horizontal"
          android:padding="10dp"
          android:autoLink="web"
          android:clickable="true"
          android:linksClickable="true"
          android:text="@string/website" />

<TextView android:id="@+id/email"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_below="@id/website"
          android:gravity="center_horizontal"
          android:padding="10dp"
          android:autoLink="email"
          android:linksClickable="true"
          android:text="@string/email" />

<TextView android:id="@+id/phone"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_below="@id/email"
          android:gravity="center_horizontal"
          android:padding="10dp"
          android:autoLink="phone"
          android:linksClickable="true"
          android:text="@string/phone" />

<TextView android:id="@+id/fax"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_below="@id/phone"
          android:gravity="center_horizontal"
          android:padding="10dp"
          android:text="@string/fax" />

Like I said.. the others are clickable and working. I've tested it on two emulators, as well as my Galaxy S4. Any thoughts why the website is not clickable?

like image 626
Josh Beckwith Avatar asked Jan 03 '14 23:01

Josh Beckwith


2 Answers

You need to call this on your textview:

TextView tv = (TextView) findViewById(R.id. website);
tv.setMovementMethod(LinkMovementMethod.getInstance());

You need to remove from your TextView:

android:autoLink="web"
android:clickable="true"
android:linksClickable="true"
like image 183
Greg Ennis Avatar answered Oct 02 '22 16:10

Greg Ennis


Add this line -

htmlContent.setMovementMethod(LinkMovementMethod.getInstance());

like image 25
Anirban Avatar answered Oct 02 '22 15:10

Anirban