Android: How can I add HTML links inside a ListView?

后端 未结 5 680
旧时难觅i
旧时难觅i 2020-12-04 23:19

How would I go about adding clickable links inside a ListView?

5条回答
  •  执笔经年
    2020-12-04 23:39

    This is done using the autoLink attribute of a TextView. Took me some time to dig through the documentation so putting it here with an example in case someone else is looking for it:

    Let us assume that you are binding your listview to a custom adapter. In that case, the following piece of code goes into your getView call:

    Code:

    textcontent.setText(Html.fromHtml(item.get_text()));
    textcontent.setAutoLinkMask(Linkify.WEB_URLS);
    

    Just put the link inside the text being passed to the setText call and you're done.

    XML:

    
    

    Hope that helps...

提交回复
热议问题