OnItemCLickListener not working in listview OnItemCLickListener not working in listview android android

OnItemCLickListener not working in listview


I just found a solution from here, but by deep clicking.

If any row item of list contains focusable or clickable view then OnItemClickListener won't work.

The row item must have a param like android:descendantFocusability = "blocksDescendants".

Here you can see an example of how your list item should look like.Your list item xml should be...row_item.xml (your_xml_file.xml)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:baselineAligned="false"    android:descendantFocusability="blocksDescendants"    android:gravity="center_vertical" >    // your other widgets here</LinearLayout>


The problem is that your layouts contain either focusable or clickable items.If a view contains either focusable or clickable item the OnItemCLickListener won't be called.

Click here for more information.

Please post one of your layout xmls if that isn't the case.


For my lists, my rows have other things that can be clicked, like buttons, so doing a blanket blocksDescendants doesn't work. Instead I add a line in the button's xml:

    android:focusable="false"

That keeps the buttons from blocking the clicks on the rows, but still lets the buttons take the clicks, too.