Skip to content Skip to sidebar Skip to footer

Trying To Catch A Click On Android Listview Item: Android:descendantfocusability="blocksdescendants" Not Working

This has been addressed in many posts on StackOverflow. The most recommended solution is to set: android:descendantFocusability='blocksDescendants' on the root layout of the list

Solution 1:

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);

Solution 2:

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!

Solution 3:

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.

Post a Comment for "Trying To Catch A Click On Android Listview Item: Android:descendantfocusability="blocksdescendants" Not Working"