Trying to catch a click on android ListView item: android:descendantFocusability=“blocksDescendants” not working

后端 未结 3 669
忘了有多久
忘了有多久 2020-12-05 15:34

This has been addressed in many posts on StackOverflow. The most recommended solution is to set:

android:descendantFocusability=\"blocksDescendants\"
         


        
3条回答
  •  心在旅途
    2020-12-05 16:05

    Just put android:focusable="false" in the row/item.xml of the listView .

    It solve all your problem. if you put an event listener on the listView .. It will not let you click on whole ListView Row. I mean

    listView.setOnClickListener(this); will not be called . because the focus moves to the row/item of the listView . By adding android:focusable="false" to the Button or ImageView on which you put an Event . It will lose their focus and the focus is gain by listView. Now you can have listView clickable as well as its descendents rows/item..

    In short just put android:focusable="false in TextView/Button or ImageView which have event Listeners in the Item/row.xml.

提交回复
热议问题