0

My textview load html text that contains links (to website, to e-mail address ...)

tv = (TextView)((Activity)mContext).findViewById(R.id.entry_webview);
tv.setText(Html.fromHtml(myPage));

I settv.setMovementMethod(LinkMovementMethod.getInstance()); to make the linke be clickable. I set tv.setTextIsSelectable(true); to make the text selectable.

What happens? TextView applies just the last setting, in this order case, text will be ONLY selectable and the link(s) won't be clickable, one setting excludes the other other one.

If I set in TextView in XML

android:autoLink="all"
android:textIsSelectable="true"

links don't work (e-mail yes).

Is there a way to make the text both clickable and selectable?

Thanks.

gderaco
  • 2,322
  • 1
  • 16
  • 18
  • possible duplicate of [TextView that is linkified and selectable?](http://stackoverflow.com/questions/14862750/textview-that-is-linkified-and-selectable) – Flow Nov 30 '13 at 16:42

2 Answers2

3

I had the same issue - this solution works for me:

The XML TextView should not have any link/selectable attributes:

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

Then, set everything programmatically respecting the following order:

textView.setText(Html.fromHtml(myHtml));
Linkify.addLinks(textView, Linkify.WEB_URLS);
textView.setTextIsSelectable(true); // API-11 and above
textView.setMovementMethod(LinkMovementMethod.getInstance());
Nilhcem
  • 837
  • 7
  • 8
0

have you tried using something like this tv.setText(Html.fromHtml("<a href='url'>link</a>"));

Emmanuel
  • 13,083
  • 4
  • 39
  • 53