How would I go about adding clickable links inside a ListView?
It's worth to mentioned that the ListView is a kind of deprecated because the RecyclerView was introduced with the API 21 (Android Lollipop).
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With