Android的 - ListView控件不接收OnItemClick与点击链接的TextView [英] Android - ListView doesn't receive OnItemClick for textview with clickable links
问题描述
我有一个包含每一行中一个TextView除了一些其他意见一个ListView。 TextView的呈现可能包含链接HTML内容。
下面code出现在列表中的适配器。
m_textview.setMovementMethod(LinkMovementMethod.getInstance());
m_textview.setText(Html.fromHtml(myhtmlcontent));
这将导致列表视图上的单击事件不再接收虽然。我决定把列表中的onclick code上的观点由适配器返回来代替。根据需要,这并不相当的工作。现在,我可以启动另一个活动时,我行中单击除TextView的任何地方。我希望用户能够点击的TextView的非链接部分,并启动另一项活动。
如果我移动的onclick到TextView的,而不是它的父视图,它现在的作品,但链接触发两个事件点击 - 一个用于链路上的点击,另一个用于TextView的(这是不希望)<。 / p>
我已经注意到,谷歌+以及在我想要的方式机器人工作窥视。我不知道如何才能实现。
这实际上是一个的 BUG 。要解决这一点,你可以添加的android:descendantFocusability =blocksDescendants
您在 ListView的
行布局XML。对于例如
&LT; LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:descendantFocusability =blocksDescendants
机器人:方向=垂直&GT; &LT;的TextView
机器人:ID =@ + ID / lblStatusMessage
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:自动链接=网
机器人:可聚焦=假
机器人:TEXTSIZE =15sp/&GT;
&LT; / LinearLayout中&GT;
来源:这和<一个href=\"http://stackoverflow.com/questions/1697908/android-how-can-i-add-html-links-inside-a-listview\">this
好运:)
I have a ListView that contains a TextView in each row besides a number of other views. The TextView renders html content which may contain links.
The below code appears in the list adapter. m_textview.setMovementMethod(LinkMovementMethod.getInstance()); m_textview.setText(Html.fromHtml(myhtmlcontent));
This causes the listview to no longer receive on click events though. I decided to put the list onclick code on the view being returned by the adapter instead. This doesnt quite work as desired. Now I can launch another activity when I click anywhere in the row except the textview. I want users to be able to click on the non-links part of the textview and launch another activity.
If I move the onclick to the textview instead of its parent view, it works but now a click on the link fires two events - one for the click on the link and another for the textview (which is not desired).
I have noticed that google+ and peep on android work in the manner I want. I'm not sure how that can be achieved.
This is actually a BUG. To resolve this you can add android:descendantFocusability="blocksDescendants"
you your ListView's
rows layout xml. For e.g
<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>
Good Luck :)
这篇关于Android的 - ListView控件不接收OnItemClick与点击链接的TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!