2

I want to set a text with a clickable link in my TextView.

Expected output: More info can be found here.

The String looks like this:

String text = "More info can be found <a href='http://google.com'>here</a>."

I set it to the TextView like this

textView.setText(Html.fromHtml(text));
textView.setMovementMethod(LinkMovementMethod.getInstance());

This should work as is but since my Textview is in a Fragment within a ViewPager clicking it won't do anything.

Anyone has experienced the same issue?

MrJM
  • 1,214
  • 1
  • 12
  • 26
  • use spannable text – Madhur Oct 19 '16 at 07:26
  • Check [this](http://stackoverflow.com/questions/2734270/how-do-i-make-links-in-a-textview-clickable), there are so many answers, give it a try and check which one work for you – Ravi Oct 19 '16 at 07:34
  • @RaviRupareliya I have, those solutions won't work in my case since the ViewPager seems to bug the normal solutions. – MrJM Oct 19 '16 at 07:43
  • @Madhur I'll try with spannable text, thanks. – MrJM Oct 19 '16 at 07:43

1 Answers1

0

You can use this in your xml attribute

android:autoLink="web"
Rahul Khurana
  • 8,577
  • 7
  • 33
  • 60
  • Autolink will only work for links that are fully visible in your textView e.g. "More info can be found on http ://g oogle.com". Mine is hidden under the label "here" thus it won't do anything. – MrJM Oct 19 '16 at 07:42
  • ok. have you tried assiging a attribute android:clickable="true" – Rahul Khurana Oct 19 '16 at 08:12
  • Yes but it doesn't seem to fix it – MrJM Oct 19 '16 at 09:37