ListView item点击无效(焦点问题)解决--descendantFocusability
2016-10-24 11:31
615 查看
item点击无效大多数情况是因为item布局中含有ImageButton,Button,CheckBox等子控件。在点击item时,这些子控件会首先获取焦点,所以点击item时变化的是子控件,item本身的点击无效。
以前处理这类问题都是使用
android:focusable=""
android:focusableInTouchMode=""
来处理,最近新发现了一个新的属性可以更好的处理这类问题,就是
android:descendantFocusability
官方API时这么写的:
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.
粗略翻译如下:
定义ViewGroup及其子控件在View中获取焦点时的关系。
属性的值有三种:
beforeDescendants: viewgroup优先其子类控件而获取到焦点
afterDescendants: viewgroup只有当其子类控件不需要获取焦点时才获取焦点
blocksDescendants: viewgroup覆盖子类控件而直接获得焦点
以上三个常量值根据需求选择一项,我使用的是blocksDescendants
以前处理这类问题都是使用
android:focusable=""
android:focusableInTouchMode=""
来处理,最近新发现了一个新的属性可以更好的处理这类问题,就是
android: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.
粗略翻译如下:
定义ViewGroup及其子控件在View中获取焦点时的关系。
属性的值有三种:
beforeDescendants: viewgroup优先其子类控件而获取到焦点
afterDescendants: viewgroup只有当其子类控件不需要获取焦点时才获取焦点
blocksDescendants: viewgroup覆盖子类控件而直接获得焦点
以上三个常量值根据需求选择一项,我使用的是blocksDescendants
相关文章推荐
- 自定义SwipeRefreshLayout 嵌套listview 并解决item点击事件焦点冲突问题
- 一般情况下ListView中的 item点击事件和 item 中的Button按钮点击事件 同时需要时,就会出现Button抢占了item的焦距问题,导致ListView中的item点击事件无效,解决
- Android listview 的 item 点击无效(无法获取焦点)的解决方法
- 解决Listview中Item中控件设置点击事件而Item点击事件失效问题
- Android ListView中嵌入Button/CheckBox后Item点击无效问题解决
- android ListView解决Item点击无效
- 我的Android进阶之旅------>Android中ListView中嵌套(ListView)控件时item的点击事件不起作的问题解决方法
- 解决“listView点击一个Item,另外几个Item也跟着改变”的问题
- android 自定义ListView 使其带单选框按钮,并解决item点击不响应的问题
- listview中的item和edittext强焦点问题怎么解决
- Android--焦点问题-ListView中item及其子控件无法响应点击事件
- Android BaseAdapter和ViewHolder 优化 解决ListView的item抢焦点问题和item错乱问题
- 解决“listView点击一个Item,另外几个Item也跟着改变”的问题
- listview里面装了别的组件导致item点击无效问题的解决方案
- 今天使用PullToRefreshListView时遇到Item点击事件失效问题,特此记下解决办法
- android 自定义ListView 使其带单选框按钮,并解决item点击不响应的问题
- ListView点击单个Item失效问题解决办法
- android中listview的item滑动删除效果(已解决listview点击问题)
- 解决listview的item点击无反应问题
- listview 中Item中含有Button 等造成Item点击无效的解决方法