2

I have a TextView that I am populating with a Spannable made from some HTML.

This code:

textView.setText(Html.fromHtml(textContent, mImageGetter, null));

displays links, but they aren't clickable. This code:

text.setMovementMethod(LinkMovementMethod.getInstance());
textView.setText(Html.fromHtml(textContent, mImageGetter, null));

doesn't display the links. The TextView is specified in the XML as

<TextView
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/another_textview"
    android:layout_marginTop="5dp"
    android:autoLink="web"
    android:textColorLink="@color/link_color_unpressed"
    android:textColor="#ffffff"
    android:textSize="18sp" />

Why does LinkMovementMethod, a method that exists entirely to make links in a TextView clickable, stop links from displaying?

Andrew Wyld
  • 6,923
  • 6
  • 49
  • 95

1 Answers1

3

The culprit was the auto-link method:

<TextView
    ...
    android:autoLink="web"
    ...
    />

Removing this line fixed the problem.

Andrew Wyld
  • 6,923
  • 6
  • 49
  • 95
  • 1
    Thanks, that was really helpful, me from the past! – Andrew Wyld May 23 '13 at 18:04
  • Thanks. This also help me a lot, but I still don't know what the function of "autoLink" is. When should I use it. @Andrew – jason May 21 '14 at 08:09
  • `autoLink` is supposed to convert detected linkable text in any `TextView` into clickable links. It works for web, email addresses, and phone numbers (well, actually, any long numbers). It's pretty handy but not as controllable as HTML. It also interacts destructively with methods available to render HTML in a `TextView` which may contain `` tags. – Andrew Wyld May 22 '14 at 17:48