Html.fromHtml不工作按要求 [英] Html.fromHtml not working as desired

查看:226
本文介绍了Html.fromHtml不工作按要求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

至于说, Html.fromHtml()不工作。这里是一个需要显示HTML格式的字符串 -

<$p$p><$c$c>&lt;p&gt;vehethtehetggebebetbefbthtehethehetheth,ethethtehethethet&lt;\\/p&gt;&lt;p&gt;ethetheyjyerjwehweryjetkteukejryjryje&lt;\\/p&gt;

这是code这我使用的用于显示文本

<$p$p><$c$c>holder.lblDesc.setText(Html.fromHtml(object.get(position).getProduct().getProductDescription()));

这是我在显示屏得到 -

在此先感谢:)

找到了解决办法

我从阿帕奇(公郎)下载库
并用这块code来显示它 -

 字符串描述= StringEscapeUtils.unescapeHtml4(object.get(位置).getProduct()getProductDescription());
holder.lblDesc.setText(Html.fromHtml(介绍));

这是结果 -


解决方案

请尝试以下操作:

 的String = \"&lt;p&gt;vehethtehetggebebetbefbthtehethehetheth,ethethtehethethet&lt;\\\\/p&gt;&lt;p&gt;ethetheyjyerjwehweryjetkteukejryjryje&lt;\\\\/p&gt;\";        TextView中的TextView =(的TextView)findViewById(R.id.textView);
        textView.setText(Html.fromHtml(s.replace(与&amp;下;,&下;)替换(与&amp; gt;中,&gt;中)));

更新:

  textView.setText(Html.fromHtml(Html.fromHtml(S)的ToString()));

您将得到的结果。

在这里输入的形象描述

As said, Html.fromHtml() is not working. Here is the string which needs to be displayed in html format -

&lt;p&gt;vehethtehetggebebetbefbthtehethehetheth,ethethtehethethet&lt;\/p&gt;&lt;p&gt;ethetheyjyerjwehweryjetkteukejryjryje&lt;\/p&gt;

This is the code which I am using for displaying text

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

This is what I get in display -

Thanks in advance :)

Found the solution

I have downloaded library from apache (commons lang) And used this piece of code for displaying it -

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

And this is the result -

解决方案

Try the following:

        String s = "&lt;p&gt;vehethtehetggebebetbefbthtehethehetheth,ethethtehethethet&lt;\\/p&gt;&lt;p&gt;ethetheyjyerjwehweryjetkteukejryjryje&lt;\\/p&gt;";

        TextView textView = (TextView) findViewById(R.id.textView);
        textView.setText(Html.fromHtml(s.replace("&lt;", "<").replace("&gt;",">")));

UPDATE:

textView.setText(Html.fromHtml(Html.fromHtml(s).toString()));

You will get the result

这篇关于Html.fromHtml不工作按要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆