如何使 listView 项中的 HTML 链接可聚焦?
我想制作一个与 Android 官方 Twitter 客户端非常相似的应用程序。
在我的listView Item中,有一个TextView,其中有一些html内容,我希望其中的链接可以是可聚焦和可点击的,我已经使用了:
getListView().setItemsCanFocus(true);
但它仍然不起作用,我不知道为什么。
布局是这样的:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="6dip"
android:background="#FFFFFF">
<ImageView android:id="@+id/avatar"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="6dip"
android:src="@drawable/default_happy_face" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:id="@+id/linearBanner"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="20dip">
<TextView android:id="@+id/txtNickname"
android:layout_width="wrap_content"
android:textColor="#1C86EE"
android:text="mmLiu" android:layout_height="fill_parent"/>
<ImageView android:id="@+id/verified"
android:layout_width="24dip"
android:layout_height="24dip"
android:paddingLeft="4dip"
android:layout_toRightOf="@id/txtNickname"
android:background="@drawable/verified"/>
<TextView android:id="@+id/txtTime"
android:textColor="#999999"
android:layout_height="fill_parent"
android:layout_alignTop="@+id/txtNickname"
android:layout_alignRight="@layout/notice_item" android:layout_toRightOf="@+id/verified" android:layout_width="fill_parent" android:gravity="right" android:text="半个小时前"/>
</RelativeLayout>
<TextView android:id="@+id/txtContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#050505"
android:text="!时尚起义 波点连衣裙原价116,现价69素雅波点拼接长裙,素色上装搭配雪纺波点短裙,优雅恬静,非你莫属!【商家地址:http://1net.cn/8wf】#服饰#" android:clickable="true"/>
</LinearLayout>
</LinearLayout>
我希望链接可以集中而不是整个项目,这个问题已经在google io中讨论过,参见这里 解决方案是 getListView().setItemsCanFocus(true); 但这对我来说不起作用。
我使用了一个扩展了 BaseAdapter 的comstimized 适配器,我不知道这是否与它有关。
有人吗?有什么帮助吗?
I wanna make an app which is quite similar to the official twitter client for android.
In my listView Item ,there is a TextView which has some html content,I hope the links within it can be focusable and clickable,I have used:
getListView().setItemsCanFocus(true);
but it still doesn't work,I don't know why.
the layout is like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="6dip"
android:background="#FFFFFF">
<ImageView android:id="@+id/avatar"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="6dip"
android:src="@drawable/default_happy_face" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:id="@+id/linearBanner"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="20dip">
<TextView android:id="@+id/txtNickname"
android:layout_width="wrap_content"
android:textColor="#1C86EE"
android:text="mmLiu" android:layout_height="fill_parent"/>
<ImageView android:id="@+id/verified"
android:layout_width="24dip"
android:layout_height="24dip"
android:paddingLeft="4dip"
android:layout_toRightOf="@id/txtNickname"
android:background="@drawable/verified"/>
<TextView android:id="@+id/txtTime"
android:textColor="#999999"
android:layout_height="fill_parent"
android:layout_alignTop="@+id/txtNickname"
android:layout_alignRight="@layout/notice_item" android:layout_toRightOf="@+id/verified" android:layout_width="fill_parent" android:gravity="right" android:text="半个小时前"/>
</RelativeLayout>
<TextView android:id="@+id/txtContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#050505"
android:text="!时尚起义 波点连衣裙原价116,现价69素雅波点拼接长裙,素色上装搭配雪纺波点短裙,优雅恬静,非你莫属!【商家地址:http://1net.cn/8wf】#服饰#" android:clickable="true"/>
</LinearLayout>
</LinearLayout>
I hope the links can be focused instead of the whole item,this issue have been discussed in the google io,see here and the solution is getListView().setItemsCanFocus(true);
But it just doesn't work for me.
I used an comstimized adapter which extends the BaseAdapter,I don't know if that has sth to do with it.
anyone? any help ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

我自己找到了解决方案:
如果你想让TextView中的链接可点击,你应该再添加一行:
除此之外
就这样了。
请参阅链接:此处
Found the solution by myself:
if you want the link in TextView clickable,you should add one more line:
besides
That's all.
see the link: here