开发中经常须要本身定义listview,去继承BaseAdapter,在adapter中按照需求进行编写,问题就出现了,可能会发生点击每个item的时候没有反应,没法获取的焦点。缘由多半是因为在你本身定义的Item中存在诸如ImageButton,Button,CheckBox等子控件(也能够说是Button或者Checkable的子类控件),此时这些子控件会将焦点获取到,因此经常当点击item时变化的是子控件,item自己的点击没有响应。 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. 继承
该属性是当一个为view获取焦点时,定义viewGroup和其子控件二者之间的关系。 ip
属性的值有三种: 开发
beforeDescendants:viewgroup会优先其子类控件而获取到焦点 it
afterDescendants:viewgroup只有当其子类控件不须要获取焦点时才获取焦点 io
blocksDescendants:viewgroup会覆盖子类控件而直接得到焦点 listview
一般咱们用到的是第三种,即在Item布局的根布局加上android:descendantFocusability=”blocksDescendants”的属性就行了, view