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

后端 未结 3 644
忘了有多久
忘了有多久 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 15:50

    Try using this inside each button layouts

     android:focusable="false"
    android:focusableInTouchMode="false"
    

    and remove other thing which you are doing for this. Also from listview. Also remove this

    android:descendantFocusability="blocksDescendants"
    

    and this too

    parent.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
            ((ViewGroup) v).setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
    
    0 讨论(0)
  • 2020-12-05 16:01

    Have you tried adding android:clickable="false" for the buttons? I just ran into a similar issue and that fixed it for me, whereas using android:focusable="false" did not.

    Good luck!

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题