安卓的Html.Form HTML [英] Android html.form html
问题描述
我想读取HTML标记一个TextView,所以我做到了这一点:
I'd like to read html tags to a TextView, so I have done this:
titolo = (TextView) this.findViewById(R.articolo.titolo);
testo = (TextView) this.findViewById(R.articolo.testo);
titolo.setText(db.getTitolo());
testo.setText(db.getTesto());
testo.setText(Html.fromHtml(testo));
不过,我有一个errore这里:testo.setText(Html.fromHtml(德图));为什么?
But i have an errore here: testo.setText(Html.fromHtml(testo)); Why?
该应用程序从数据库中检索数据,所以我希望,如果我写入数据库,例如您好,这是使用格式化为粗体html.fromhtml
This application retrieves data from a database so I hope that if I write into the database, for example hello this is formatted as bold using html.fromhtml
推荐答案
在你的榜样,你要发送的TextView到fromHtml,你应该提供的字符串变量。该字符串可以包含HTML标签。
In your example you're sending TextView to fromHtml and you should deliver String variable. That String could contain HTML tags.
TextView testo = (TextView) findViewById(R.articolo.testo);
String formattedText = "This is <b>bold</b>";
testo.setText(Html.fromHtml(formattedText));
当然,你可以从数据库得到的字符串。我不知道如何工作的getTesto()方法,但如果它返回的字符串,你可以写:
Of course you could get String from DB. I don't know how works your getTesto() method, but if it returns String you could write:
TextView testo = (TextView) findViewById(R.articolo.testo);
String formattedText = db.getTesto();
testo.setText(Html.fromHtml(formattedText));
这篇关于安卓的Html.Form HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!