關於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失效,估計是一些子控件搶佔了焦點)

 

 

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