0

I have html string. I need to show my it in my TextView. Here is my code:

tvText.setText(Html.fromHtml(htmlString));

Html string contains some text, but may also contains links. I need to detect if a string contains a link, make part of that string clickable.

I can do a search for links in a string myself and then use SpannableString and ClickableSpan.

But perhaps there is some way to set a click in html and then the mobile application will be able to react for some reason and make part of the string clickable.

Please help me.

UPD: I can request an html string in any form, so I need to understand what it should be in order to process a click in a mobile application without any search for links in string.

testivanivan
  • 967
  • 13
  • 36
  • What does the String look like? (Mainly the link part) – TheLibrarian Oct 19 '22 at 07:32
  • @TheLibrarian, I can request a String in any form, I just need to know in which one so that I can associate a click with a mobile application. Unfortunately I am very weak in html – testivanivan Oct 19 '22 at 07:39

1 Answers1

1

Try to wrap your links in html <a> tags and set movement method to your textView like this:

textView.setText(Html.fromHtml("This is a <a href=\"https://google.com/\">link</a>"));
textView.setMovementMethod(LinkMovementMethod.getInstance());
shmakova
  • 6,076
  • 3
  • 28
  • 44