ListView中点击Item没有任何响应

不多说,上代码:如下图

红色方框的东西,

android:descendantFocusability=”blocksDescendants”

如果不添加的话,在android的8.0手机上点击没有响应,(本人在Android 8.0手机上亲自测过,不添加,出现点击没有任何的响应)。

可能原因:  自己定义的Item中存在诸如ImageButton,Button,CheckBox等子控件(也可以说是Button或者Checkable的子类控件),此时这些子控件会将焦点获取到,所以常常当点击item时变化的是子控件,item本身的点击没有响应。即在Item布局的根布局加上android:descendantFocusability=”blocksDescendants”的属性就好了。

简单上网查了一下关于这个属性的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会覆盖子类控件而直接获得焦点

 

努力做一个伪程序员, 不管道路有多么的艰苦......
原文地址:https://www.cnblogs.com/xumBlog/p/7852304.html