机器人:不能点击的ListView一行的ImageButton [英] android: cant click on listview row with imagebutton
问题描述
我有一个列表视图的麻烦。其项目(行)具有的ImageButton。 的ImageButton有安卓的onClick所以这个onclick事件是工作,但点击行不工作。如果我从行项目中删除的ImageButton,点击就行作品(列表视图具有正确的onclick听者)。我该如何解决呢?我需要onclick事件当ImageButton的和非标准click事件,当用户选择行用户点击(不点击的ImageButton,但点击行)
我的ListView:
< ListView控件的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / restaurants_list
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:分隔=@色/ list_devider
机器人:dividerHeight =1DP
机器人:cacheColorHint =@色/ list_background/>
不幸的是,
机器人:可调焦=假
机器人:focusableInTouchMode =假
为的ImageButton
不起作用。
我终于找到了解决办法<一href="http://mylifewithandroid.blogspot.com/2011/08/focus-problems-with-list-rows-and.html">here.在你的布局XML这些项目中,添加
安卓descendantFocusability =blocksDescendants
到根视图。
它完美的的ListView
,有的ImageButton
秒。据<一href="http://developer.android.com/reference/android/view/ViewGroup.html#attr_android%3adescendantFocusability">official参考, blocksDescendants
表示的ViewGroup
将阻止其后代接收焦点。
I have trouble with listview. its items (rows) have imagebutton. imagebutton has "android:onClick" so this onclick event is working, but click on row doesnt work. if i remove imagebutton from row item, click on row works (listview has correct onclick listner). How can i fix it ? i need onclick event when user click on imagebutton and standart click event, when user select row (not click the imagebutton but click the row)
my listview :
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/restaurants_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="@color/list_devider"
android:dividerHeight="1dp"
android:cacheColorHint="@color/list_background" />
Unfortunately,
android:focusable="false"
android:focusableInTouchMode="false"
doesn't work for ImageButton
.
I finally found the solution here. In your layout xml for those items, add
android:descendantFocusability="blocksDescendants"
to the root view.
It works perfectly for a ListView
that has ImageButton
s. According to official reference, blocksDescendants
means that the ViewGroup
will block its descendants from receiving focus.
这篇关于机器人:不能点击的ListView一行的ImageButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!