机器人:不能点击的ListView一行的ImageButton [英] android: cant click on listview row with imagebutton

查看:96
本文介绍了机器人:不能点击的ListView一行的ImageButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表视图的麻烦。其项目(行)具有的ImageButton。 的ImageButton有安卓的onClick所以这个onclick事件是工作,但点击行不工作。如果我从行项目中删除的ImageButton,点击就行作品(列表视图具有正确的onclick听者)。我该如何解决呢?我需要onclick事件当ImageButton的和非标准click事件,当用户选择行用户点击(不点击的ImageButton,但点击行)

我的ListView:

 < ListView控件的xmlns:机器人=htt​​p://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 ImageButtons. According to official reference, blocksDescendants means that the ViewGroup will block its descendants from receiving focus.

这篇关于机器人:不能点击的ListView一行的ImageButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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