简体   繁体   English

将HTML添加到ListView中的textView中

[英]Add HTML to a textView in a ListView

HI I have a question I can't seem to figure out. 嗨,我有一个我似乎无法解决的问题。 I am trying to add HTML to a textView that is a column in a ListView. 我正在尝试将HTML添加到作为ListView中一列的textView中。 I have a 3 coulmn row for a ListView. 我有一个3 Coulmn行的ListView。

My code to add the html to a textView is: 我将html添加到textView的代码是:

TextView mTextSample = new TextView(this);
String text = "Visit my <a href='http://www.newblog.com'>blog</a>";
mTextSample.setText(Html.fromHtml(text));

Then I have a HashMap in which I add mTextSample.getText() too: 然后我有一个HashMap,其中也添加了mTextSample.getText():

HashMap Object, Object map = new HashMap Object, Object();              
map.put("c1", "STATUTE");
map.put("c0", "");
map.put("c2", mTextSample.getText()); 
mylist.add(map);

Then this row is added to my ListView (R.id.CELL2 should have the html in it): 然后将此行添加到我的ListView中(R.id.CELL2应该包含html):

final ListView listnew = (ListView) findViewById(R.id.lvdata);

SimpleAdapter mSchedulenew = new SimpleAdapter(this, (List<? extends Map<String, ?>>) mylist, R.layout.row, 
new String[] {"c1","c0","c2"}, new int[] {R.id.CELL1,R.id.CELLBlank, R.id.CELL2}); 
listnew.setAdapter(mSchedulenew); 

But when run only the "Visit my blog" is displayed (which is correct but no link is generated). 但是在运行时,仅显示“访问我的博客”(这是正确的,但未生成任何链接)。 It seems like the html is being filter out when I add this row to the listView. 当我将此行添加到listView时,似乎正在过滤掉html。

This should do it - 这应该做到-

TextView mTextSample = new TextView(this);
mTextSample.setMovementMethod(LinkMovementMethod.getInstance());

String text = "Visit my <a href='http://www.newblog.com'>blog</a>";
mTextSample.setText(Html.fromHtml(text));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM