关于Listview中item点击失效问题解决

百度了一下这个问题,方案有很多,这里我就给出我自己的成功案例:

我是使用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失效,估计是一些子控件抢占了焦点)

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章