android
  • html
  • listview
  • hyperlink
  • 2011-06-24 51 views 0 likes 
    0

    HI我有一個問題,我似乎無法弄清楚。我正在嘗試將HTML添加到作爲ListView中的列的textView中。我有一個ListView的3 coulmn行。將HTML添加到ListView中的textView中

    我的代碼的HTML代碼添加到一個TextView是:

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

    然後,我必須在我添加mTextSample.getText(一個HashMap)太:

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

    但是,只運行「訪問我的博客」displaye d(這是正確的,但不生成鏈接)。當我將這行添加到listView時,好像html被過濾掉了。

    回答

    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)); 
    
    相關問題