问题:当listView内部item中有button等控件时,会发现listView的点击事件没作用了。现在的需求是,既能响应每个item的点击,也要恢复listView的触摸事件
方案:
descendantFocusability属性解决此问题。
Defines the relationship between the ViewGroup and its descendants when looking for a View to take focus.
descendantFocusability属性值得含义
beforeDescendants:viewgroup会优先其子类控件而获取到焦点
afterDescendants:viewgroup只有当其子类控件不需要获取焦点时才获取焦点
blocksDescendants:viewgroup会覆盖子类控件而直接获得焦点 (*)
解决:
在子item的布局中添加该属性即可。