I have the following code executed in onBindViewHolder() of a RecyclerView:
String commentPrompt = "<html><b>" + ((ViewHolder) viewHolder).comment.getText().toString() + "</b></html>";
TextView commentText = new TextView(context);
commentText.setText(item.comment);
Linkify.addLinks(commentText, Linkify.WEB_URLS);
if (!item.comment.contains("www.") || item.comment.contains("https://")) {
((ViewHolder) viewHolder).comment_text.setText(Html.fromHtml(commentPrompt + BLANK + item.comment, Html.FROM_HTML_MODE_COMPACT));
} else {
((ViewHolder) viewHolder).comment_text.setText(Html.fromHtml(commentPrompt + BLANK + commentText.getText(), Html.FROM_HTML_MODE_COMPACT));
}
((ViewHolder) viewHolder).comment_text.setMovementMethod(LinkMovementMethod.getInstance());
The problem is that when
((ViewHolder) viewHolder).comment_text.setText(Html.fromHtml(commentPrompt + BLANK + commentText.getText(), Html.FROM_HTML_MODE_COMPACT));
is called, commentText is not linkified (text at the bottom):
But when I change the code to the following:
((ViewHolder) viewHolder).comment_text.setText(commentText.getText());
The URLs do get linkified, but I lose the "Comment:" prompt:
How can I preserve the bold-faced prompt and still display live links?