2012-02-09 87 views
3

我在android中有一個自定義列表視圖,每個項目由幾個文本視圖組成。其中一個文本視圖包含HTML文本,其中一些包含<a>標籤。我正在使用HTML.fromHTML()方法將其轉換爲可由textView讀取的String,但鏈接不可點擊。如果我讓他們有焦點,那麼列表項不再是可點擊的,並且鏈接仍然不起作用。Android中的HTML鏈接列表視圖

那麼,如果在鏈接以外的任何地方點擊列表項目,我該如何使鏈接可點擊並保持正常的點擊功能?

編輯:我的代碼:

if (convertView == null) { 
     LayoutInflater vi = (LayoutInflater) context 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView = vi.inflate(R.layout.email_list_item, null); 
    } 


    TextView contentView = (TextView) convertView 
      .findViewById(R.id.content); 

    Email e = items.get(position); 

    CharSequence content = ""; 
    if (e.getContent() != null) { 
     content = Html.fromHtml(e.getContent()); 
    } 

    contentView.setText(content); 
    return convertView; 

回答

3

您需要設置AutoLinkMask

textcontent.setText(Html.fromHtml(text.get_text())); 
textcontent.setAutoLinkMask(Linkify.WEB_URLS); 
+0

這樣可以阻止列表項目本身被點擊,我仍然希望他們聽到點擊事件,如果它不是一個鏈接被點擊。 – leedsunited92 2012-02-09 23:55:37

+1

你可以發佈你的代碼嗎? – kosa 2012-02-09 23:57:35

+0

將其添加到原始帖子。 – leedsunited92 2012-02-10 19:08:18

0

在您的自定義列表視圖行XML加入這一行。

列表行XML:

android:autoLink="web" 
android:linksClickable="true" 

但它的顯示列表視圖文本作爲HTML標籤象下面這樣:

<a href= "http://google.com">Google </a> 

如果我添加Html.fromHtml(文本)內部的再鏈接沒有更多的點擊。