我有一个 ListView,除了许多其他视图之外,每行还包含一个 TextView。 TextView 呈现可能包含链接的 html 内容。
以下代码出现在列表适配器中。
m_textview.setMovementMethod(LinkMovementMethod.getInstance());
m_textview.setText(Html.fromHtml(myhtmlcontent));
但这会导致列表视图不再接收单击事件。我决定将列表 onclick 代码放在适配器返回的视图上。这并不完全按预期工作。现在,当我单击行中除文本视图之外的任意位置时,我可以启动另一个活动。我希望用户能够单击文本视图的非链接部分并启动另一个活动。
如果我将 onclick 移动到文本视图而不是其父视图,它可以工作,但现在单击链接会触发两个事件 - 一个用于单击链接,另一个用于文本视图(这是不需要的)。
我注意到 android 上的 google+ 和 peep 以我想要的方式工作。我不确定如何实现这一点。
这实际上是一个BUG https://code.google.com/p/android/issues/detail?id=3414#c27。要解决此问题,您可以添加android:descendantFocusability="blocksDescendants"
你你你的ListView's
行布局 xml。例如
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical" >
<TextView
android:id="@+id/lblStatusMessage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoLink="web"
android:focusable="false"
android:textSize="15sp" />
</LinearLayout>
来源 :this https://code.google.com/p/android/issues/detail?id=3414#c27 and this https://stackoverflow.com/questions/1697908/android-how-can-i-add-html-links-inside-a-listview
祝你好运 :)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)