不多说,上代码:如下图

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.

ListView中点击Item没有任何响应

 

该属性是当一个为view获取焦点时,定义viewGroup和其子控件两者之间的关系。

属性的值有三种:

        beforeDescendants:viewgroup会优先其子类控件而获取到焦点

        afterDescendants:viewgroup只有当其子类控件不需要获取焦点时才获取焦点

        blocksDescendants:viewgroup会覆盖子类控件而直接获得焦点

 

相关文章:

  • 2021-07-08
  • 2021-04-15
  • 2022-12-23
  • 2022-02-04
  • 2021-09-19
  • 2022-12-23
  • 2022-12-23
  • 2022-01-23
猜你喜欢
  • 2021-06-22
  • 2021-12-05
  • 2021-09-22
  • 2021-08-13
  • 2021-09-16
  • 2021-12-05
  • 2022-01-11
相关资源
相似解决方案