我正在尝试在我的Android应用中将带有html标签的文本显示为纯文本。我尝试过使用一些html方法,但他们最后还是用了一个空格而不是我的文本。
final ptaModel current = mDataList.get(position);
Spanned content;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N)
{
content = Html.fromHtml(current.getContent(), FROM_HTML_MODE_LEGACY);
}
else
{
content = Html.fromHtml(current.getContent());
}
holder.date.setText(current.getDate());
holder.minutes.setText(content);
holder.title.setText(current.getTitle());
我找到了一个答案,说要使用上面的代码,但我最终得到一个空的textview而不是纯文本。
这是我用html标签收到的内容:
"content":"<p> <\/p><p>Attendees:<\/p><p> <br><\/p><p>Suzy Bullett, Lisa Wagner, Jamie Flint,
Camilla Logeske, Jennifer Legault, Emily Hidalgo<\/p><p> <br><\/p><p> <\/p><p>
<br><\/p><p>Meeting called to order at 7:30am<\/p><p> <br><\/p><p> <\/p><p>
<br><\/p><p><b style=\"bidi-font-weight:normal\">New Business-<\/b><\/p><p> <br><\/p>
<p class=c1 style=\"text-indent:-.25in;list:l1 level1 lfo1\">1.
How to spend money made from Fall Fundraiser <\/p><p> <br><\/p>
<p class=c2 style=\"margin-left:.75in;add-space: auto;text-indent:-.25in;list:l0 level1 lfo2\">
A. Water bottle filler $1000 (possibly pay for with jogathon funds)<\/p><p>
<br><\/p><p class=c2 style=\"margin-left:.75in;add-space: auto;text-indent:-.25in;list:l0 level1 lfo2\">B.
Chrome book cart $1500, $400 for Chrome Books<\/p><p> <br><\/p>
<p class=c2 style=\"margin-left:.75in;add-space: auto;text-indent:-.25in;list:l0 level1 lfo2\">
C. Teacher laptops, 8 needed<\/p><p> <br><\/p>
<p class=c2 style=\"margin-left:.75in;add-space: auto;text-indent:-.25in;list:l0 level1 lfo2\">
D. AR $4000<\/p><p> <br><\/p><p class=c2 style=\"text-indent:-.25in;list:l1 level1 lfo1\">
2. PTA membership drive, end home form and put on Facebook<\/p><p>
<br><\/p><p class=c2 style=\"text-indent:-.25in;list:l1 level1 lfo1\">3.
Fall Carnival<\/p><p> <br><\/p><p class=c2 style=\"margin-left:.75in;add-space: auto;text-indent:-.25in;list:l2
level1 lfo3\">A. First meeting 9\/22<\/p><p> <br><\/p>
<p class=c2 style=\"margin-left:.75in;add-space: auto;text-indent:-.25in;list:l2 level1 lfo3\">
B. Tickets<\/p><p> <br><\/p><p class=c2 style=\"margin-left:.75in;add-space:
auto;text-indent:-.25in;list:l2 level1 lfo3\">C. Dinner, Amy Burrows<\/p><p>
<br><\/p><p class=c2 style=\"margin-left:.75in;add-space: auto;text-indent:-.25in;list:l2 level1 lfo3\">D.
Raffle <\/p><p> <br><\/p><p class=c2 style=\"margin-left:.75in;add-space:
auto;text-indent:-.25in;list:l2 level1 lfo3\">E. Auction<\/p><p> <br>
<\/p><p class=c2 style=\"margin-left:.75in;add-space: auto;text-indent:-.25in;list:l2 level1 lfo3\">
F. Games\/redemption center<\/p><p> <br><\/p><p class=c2 style=\"margin-l
eft:.75in;add-space: auto;text-indent:-.25in;list:l2 level1 lfo3\">G. Cake walk<
\/p><p> <br><\/p><p class=c2 style=\"margin-left:.75in;add-space: auto;text-indent:-.25in;list:l2 level1 lfo3\"
>H. Talked about asking for monetary donations instead of doing baskets, try to ra
ise the money for teacher laptops this way.<\/p><p> <br><\/p><p class=c2 style=\"text-indent:-.25in;list:l1 leve
l1 lfo1\">4. Upgrade VITAL room computer<\/p><p> <br><\/p><p class=c2 style
=\"text-indent:-.25in;list:l1 level1 lfo1\">5. Add babysitters for kindergar
ten back to school night to budget<\/p><p> <br><\/p><p class=c3 style=\"text-indent:-.25in;list:l1 level1 lfo1\">
6. Treasurer’s report- Jamie<\/p><p> <br><\/p><p style=\"margin-left:.25in\">
<\/p><p> <br><\/p><p style=\"margin-left:.25in\">Meeting Adjourned 8:20<\/p><p> <br"}