Html.fromHtml无法正常工作

时间:2015-08-27 07:01:26

标签: android

如上所述,Html.fromHtml()无效。这是需要以html格式显示的字符串 -

<p>vehethtehetggebebetbefbthtehethehetheth,ethethtehethethet<\/p><p>ethetheyjyerjwehweryjetkteukejryjryje<\/p>

这是我用来显示文字的代码

holder.lblDesc.setText(Html.fromHtml(object.get(position).getProduct().getProductDescription()));

这就是我展示的内容 - This is what I get in display

提前致谢:)

找到解决方案

我从apache (commons lang)下载了库 并使用这段代码来显示它 -

String description = StringEscapeUtils.unescapeHtml4(object.get(position).getProduct().getProductDescription());
holder.lblDesc.setText(Html.fromHtml(description));

这就是结果 - enter image description here

2 个答案:

答案 0 :(得分:0)

这样做

holder.lblDesc.setText(Html.fromHtml("<p>"+object.get(position).getProduct().getProductDescription()+"</p>"));

答案 1 :(得分:0)

这很简单,肯定会奏效。

    String s1 = Html.fromHtml(object.get(position).getProduct().getProductDescription()).toString();

       holder.lblDesc.setText(Html.fromHtml(s1));