区分listview的item和Button的点击事件
2018-04-02 16:23
295 查看
在ListView中加入Button这类的有 “点击” 事件的widget,发现原来listview的itemclick居然失效了,后来在网上查资料终于得以解决。
ListView 和 其它能触发点击事件的widget无法一起正常工作的原因是加入其它widget后,ListView的itemclick事件将无法触发,被其它widget的click事件屏蔽。
解决办法:
在item中,包含button的item的Layout中加入属性 android:descendantFocusability= “blocksDescendants”
在buttion的属性加入android:focusable=”false”
ListView 和 其它能触发点击事件的widget无法一起正常工作的原因是加入其它widget后,ListView的itemclick事件将无法触发,被其它widget的click事件屏蔽。
解决办法:
在item中,包含button的item的Layout中加入属性 android:descendantFocusability= “blocksDescendants”
在buttion的属性加入android:focusable=”false”
问题解决,两个click事件不再冲突了!
下面我是程序中的部分代码,该布局文件时listview中的item的布局,<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" style="@style/ListItem" android:layout_width="fill_parent" android:layout_height="fill_parent" android:descendantFocusability="blocksDescendants" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone" /> <ImageView android:layout_width="45dip" android:layout_height="45dip" android:layout_alignParentLeft="true" android:layout_gravity="center" android:background="@drawable/imageview_background" android:scaleType="fitXY" /> <Button android:layout_width="@dimen/btn_attention_width" android:layout_height="@dimen/btn_attention_height" android:layout_alignParentRight="true" android:background="@drawable/button_selector_gradient" android:focusable="false" android:text="关注" /> </RelativeLayout>
相关文章推荐
- 区分listview的item和Button的点击事件
- 想实现在ListFragment里面的ListView的item里面的Button的点击事件
- listview 的onitemlongclick阿和onitemclick冲突,item中还有button的点击事件
- listview 的onitemlongclick阿和onitemclick冲突,item中还有button的点击事件
- ListView的Item中设置Button点击事件优化,避免重复new Listener
- ListView控件中item中实现的Button的点击事件
- ListView点击事件失效(item里面有button按钮控件)解决方法
- Android中ListView(gridview)的item中有button等子点击控件时不能响应点击事件的原因
- ListView的item中有button ImageButton CheckBox EditText等时 点击事件失效问题的解决
- listview 嵌套checkbox响应item点击和button点击事件
- listview的item里面有Button,并给其设置了点击事件,而且有效可点击,但是listview的item点击事件却失效了
- ListView里面添加Button之类可点击事件Item不可点击的处理方法
- Android基础:listview的item点击事件会使里面的Button也出现按压的效果
- 一般情况下ListView中的 item点击事件和 item 中的Button按钮点击事件 同时需要时,就会出现Button抢占了item的焦距问题,导致ListView中的item点击事件无效,解决
- ListView item中有button或EditText时 点击事件失效问题的解决
- ListView的item中的button被点击时,item也能相应点击事件
- Android listview的item中button的点击事件 item和button 可同时点击
- listview的onitemlongclick和onitemclick冲突,item中的button点击事件
- ListView item点击事件和button点击事件并存
- 想实现在ListFragment里面的ListView的item里面的Button的点击事件