Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 415
Legend Avatar asked Nov 08 '09 20:11

Legend


People also ask

Is ListView deprecated Android?

It's worth to mentioned that the ListView is a kind of deprecated because the RecyclerView was introduced with the API 21 (Android Lollipop).


1 Answers

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:

<TextView
                android:id="@+id/txtview"
                android:autoLink="web"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:text="put your link here"/>

Hope that helps...

like image 158
Legend Avatar answered Oct 11 '22 13:10

Legend