不能单击带有imagebutton的listview行 [英] can't click on listview row with imagebutton

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

问题描述

我在使用listview时遇到麻烦.其项目(行)具有imagebutton. imagebutton具有"android:onClick",因此此onclick事件有效,但对行的单击不起作用.如果我从行项目中删除imagebutton,请单击行作品(列表视图具有正确的onclick列表器).我该如何解决?当用户单击imagebutton和标准点击事件时,我需要onclick事件,当用户选择行时(不是单击imagebutton而是单击行)

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)

我的列表视图:

<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" /> 

推荐答案

不幸的是,

android:focusable="false"
android:focusableInTouchMode="false"

不适用于ImageButton.

我终于在此处.在这些项目的布局xml中,添加

I finally found the solution here. In your layout xml for those items, add

android:descendantFocusability="blocksDescendants" 

进入根视图.

它非常适合具有ImageButtonListView.根据官方参考blocksDescendants表示ViewGroup将阻止其后代获得焦点.

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.

这篇关于不能单击带有imagebutton的listview行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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