百度了一下这个问题,方案有很多,这里我就给出我自己的成功案例:
我是使用descendantFocusability来解决的,
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会覆盖子类控件而直接获得焦点
我的做法是在根布局添加,如下所示:
android:descendantFocusability="blocksDescendants"
实测解决了Listview中某些item的点击事件失效问题。(我这里是某些item失效,估计是一些子控件抢占了焦点)