I know there are lots of answers to this question but I cant seem to get it to work... I have a ListView with some custom items consisting of TextViews and ImageViews.
I receive some data through an XML feed. One of the elements contains HTML like:
<![CDATA[ <p>My text <a href="http://myhost.com/link/to/fM" target="_blank">click here</a>.</p> ]]>
In my adapter I have this method:
private static Spanned fromHtml(String html){
Spanned result;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
result = Html.fromHtml(html,Html.FROM_HTML_MODE_LEGACY);
} else {
result = Html.fromHtml(html);
}
return result;
}
I'm on Android 6 so I end up in the "else" section.
I use a "holder" class to define all my TextViews and ImageViews needed for a ListView item. The holder instance is assigned like this:
view.setTag(myHolder);
and the TextView in question I populate like this:
String s = fromHtml(xmlItem.Description).toString();
myHolder.description.setText(fromHtml(s));
If I omit the
fromHtml(s)
and just setText(s) I get all the tags from my CDATA rendered
I really just want the text "click here" to be rendered as a clickable link...
What am I doing wrong?