ListView中嵌入button,点击监听无响应的解决方案
来源:互联网 发布:windows 98下载 编辑:程序博客网 时间:2024/06/09 14:42
在ListView的item的根节点中设置如下属性:
android:descendantFocusability="blocksDescendants"
具体原因如下:
开发中很常见的一个问题,项目中的listview不仅仅是简单的文字,常常需要自己定义listview,自己的Adapter去继承BaseAdapter,在adapter中按照需求进行编写,问题就出现了,可能会发生点击每一个item的时候没有反应,无法获取的焦点。原因多半是由于在你自己定义的Item中存在诸如ImageButton,Button,CheckBox等子控件(也可以说是Button或者Checkable的子类控件),此时这些子控件会将焦点获取到,所以常常当点击item时变化的是子控件,item本身的点击没有响应。
这时候就可以使用descendantFocusability来解决啦,API描述如下:
android:descendantFocusability
Defines the relationship between the ViewGroup and its descendants when looking for a View to take focus.
Must be one of the following constant values.
该属性是当一个为view获取焦点时,定义viewGroup和其子控件两者之间的关系。
属性的值有三种:
beforeDescendants:viewgroup会优先其子类控件而获取到焦点
afterDescendants:viewgroup只有当其子类控件不需要获取焦点时才获取焦点
blocksDescendants:viewgroup会覆盖子类控件而直接获得焦点
通常我们用到的是第三种,即在Item布局的根布局加上android:descendantFocusability=”blocksDescendants”的属性就好了。
- ListView中嵌入button,点击监听无响应的解决方案
- ListView中嵌入Button,并响应Button点击事件
- ListView中嵌入Button,并响应Button点击事件
- ListView中嵌入布局中有Button,如何响应Button点击事件
- Android listView 中响应Button点击事件
- Android listView 中响应Button点击事件
- Android listView 中响应Button点击事件
- Android listView 中响应Button点击事件
- activity响应listview中button点击事件
- listview的itemClick监听无响应问题
- android listView 点击无响应的解决办法
- android listView 点击无响应的解决方法
- android listView 点击无响应的解决方法
- android listView 点击无响应的解决方法
- android listView 点击无响应的解决办法
- ListView的Item点击事件无响应
- GridView, ListView的item中嵌入button或其他view导致item点击失效的研究
- android listview的item布局中含有button,不会响应listview的onitemclick监听 以及 onitemlongclick监听问题解决
- 告诉你一个真实的 OpenStack:都谁在用,用来干什么?
- ListView--内容不显示
- POJ 2823 Sliding Window <速度特快 单调队列>
- 图的最短路径问题
- 打印蛇形矩阵
- ListView中嵌入button,点击监听无响应的解决方案
- Git Commit前取消add 操作(利用git reset操作)
- 微软面试100题系列---判断整数序列是否为二叉查找树的后序遍历
- MFC ShowLog(CString strLog)
- C语言_统计本件中各长度字符串出现的次数
- Linux 下编译安装软件,找不到共享库 xx.so 的解决办法
- Effective Modern C++ 条款26 避免对通用引用进行重载
- 仿实例开发----一个简单的视频播放器
- oracle 新增表空间的几种方法