0

I have simple task: to display in TextView some HTML code.

The implementation is:

   <TextView
        android:id="@+id/subtitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="#808080"
        android:textSize="16.5dip"
        android:lineSpacingExtra="4dip"/>

And the code:

    mSubtitle.setText(Html.fromHtml(mData.answer));

Here is example of the mData.answer:

Some text <a href="url1">link1</a>, some text <a href="url2">link2</a>, etc

I suppose this is not so heavy code to display in the TextView. And it works, but links in my TextView are not clickable. How to enable this feature?

bvitaliyg
  • 3,155
  • 4
  • 30
  • 46
  • Put this in your `TextView` : `android:linksClickable="true"` or check that http://stackoverflow.com/a/17544212/1106598 Plus, there are tons of questions like this. Please check them before you post any question – Gokhan Arik Jul 31 '14 at 18:13
  • @GokhanArik this is not same question. Most of them operating with one single link in text, which is unacceptable in this case. And I've tried to apply this attributes(without results) before posting question. – bvitaliyg Jul 31 '14 at 18:28
  • It doesn't matter, logic is the same. I posted answer now check and let me know – Gokhan Arik Jul 31 '14 at 19:01

1 Answers1

0

Try this,

<TextView
        android:id="@+id/subtitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="#808080"
        android:textSize="16.5dip"
        android:autoLink="web"
        android:linksClickable="true"
        android:lineSpacingExtra="4dip"/>
        />

autoLink will solve your problem, if it doesn't try this also

mSubtitle.setText(Html.fromHtml(mData.answer));
mSubtitle.setMovementMethod(LinkMovementMethod.getInstance());
Gokhan Arik
  • 2,626
  • 2
  • 24
  • 50