ListView防止点击事件被子view点击事件屏蔽
来源:互联网 发布:lumia2520 linux 编辑:程序博客网 时间:2024/04/28 18:04
ListView防止点击事件被子view点击事件屏蔽
在使用ListView的时候,我们使用adapter中画我们自定义item项时,一般会加上Button事件,或者Imagebutton,但是效果却不是我们想象的那么简单,因为你会发现ListView的itemclick事件就不生效了,原因很简单Button的onClick事件抢占了ListView的itemclick,我们只需在布置文件中添加下述代码屏蔽Button的onClick事件的焦点即可:
在list的配置xml的根节点添加属性android:descendantFocusability="blocksDescendants",还有就是在要添加事件的控件上加android:focusable="false"。
我们看看
android:descendantFocusabilityDefines the relationship between the ViewGroup and its descendants when looking for a View to take focus.
Must be one of the following constant values.
ConstantValueDescriptionbeforeDescendants0The ViewGroup will get focus before any of its descendants.afterDescendants1The ViewGroup will get focus only if none of its descendants want it.blocksDescendants2The ViewGroup will block its descendants from receiving focus最后一个是ViewGroup将阻止其后代接收焦点
所以 如果Listview中想不被屏蔽OnItemClickListener事件的话 那么久在item中的布局中 的最顶层布局加入这句话
想要阻止哪个widget 就在哪个widget设置focusable="false"
具体的实例看下面的
http://blog.chinaunix.net/space.php?uid=9935135&do=blog&id=181843
- ListView防止点击事件被子view点击事件屏蔽
- Android屏蔽ListView的Item点击事件
- android屏蔽listview 的item点击事件
- Android屏蔽ListView的Item点击事件
- Android屏蔽ListView的Item点击事件
- Android屏蔽ListView部分Item点击事件
- 屏蔽listview中的item点击事件,但不屏蔽item子控件的点击事件
- Viewgroup被子VIew抢焦点,导致Item无法响应点击事件。
- listview的点击事件
- ListVIew点击事件失效
- ListView点击事件失效
- ListVIew点击事件失效
- ListVIew点击事件失效
- ListVIew点击事件失效
- ListView中的点击事件
- ListView OnItemClickListener点击事件
- listview点击事件失效
- listview中点击事件
- ORA-01455错误的处理方法
- anacron和cron服务有什么区别
- GetLastError错误码
- ASP.NET 经典60道面试题
- ASP.NET基础知识
- ListView防止点击事件被子view点击事件屏蔽
- SQLServer 存储过程中不拼接SQL字符串实现多条件查询
- 用户体验超棒并且功能强大使用简单的javascript表单验证 - Parsley.js
- 17个新手常用代码整理---
- oracle 使用递归的性能提示
- <MSDN笔记>Lambdas with the Standard Query Operators
- jQuery的Select操作集合
- MySQL追加(附加)字符串到表中某text字段的所有行
- java中的值传递和引用传递