Reputation: 1514
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.
Upvotes: 0
Views: 222
Reputation: 6426
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());
Upvotes: 1