Android:如何在 ListView 中添加 HTML 链接? [英] Android: How can I add HTML links inside a ListView?

查看:26
本文介绍了Android:如何在 ListView 中添加 HTML 链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将如何在 ListView 中添加可点击的链接?

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

推荐答案

这是使用 TextView 的 autoLink 属性完成的.我花了一些时间来仔细阅读文档,所以把它和一个例子放在这里,以防其他人正在寻找它:

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:

让我们假设您将列表视图绑定到自定义适配器.在这种情况下,以下代码将进入您的 getView 调用:

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:

代码:

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

只需将链接放入传递给 setText 调用的文本中即可.

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"/>

希望有帮助...

这篇关于Android:如何在 ListView 中添加 HTML 链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆