【问题标题】:Add HTML to a textView in a ListView将 HTML 添加到 ListView 中的 textView
【发布时间】:2011-09-22 04:33:13
【问题描述】:

您好,我有一个问题,我似乎无法弄清楚。我正在尝试将 HTML 添加到作为 ListView 中的列的 textView。我有一个 3 列的 ListView 行。

我将 html 添加到 textView 的代码是:

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

然后我有一个 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);

然后将这一行添加到我的 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); 

但运行时只显示“访问我的博客”(这是正确的,但没有生成链接)。当我将此行添加到 listView 时,似乎 html 正在被过滤掉。

【问题讨论】:

    标签: android html listview hyperlink


    【解决方案1】:

    应该这样做 -

    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));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-08
      • 1970-01-01
      • 1970-01-01
      • 2013-09-05
      相关资源
      最近更新 更多