Why is the following code being rendered in plain font instead of bold?

26 Views Asked by At

Consider the following Android code executed in onBindViewHolder() of a RecyclerView adapter:

    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));
    }

The field commentPrompt is rendered in bold font, as expected. But if I remove the text commentText.getText(), commentPrompt is rendered in plain font. Why?

0

There are 0 best solutions below