Search code examples
androidtextviewlistviewitemonitemclicklistener

Custom ListView item click event is not working


My app is supporting ADA compliance. For that I have added

 android:focusable="true"

property for custom ListView items (3-4 TextViews). But after this my ListView item click event is not working. When I removed above property from list items, it is working fine. But for ADA compliance I need this. How can I resolve this issue?

EDIT:

    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:nextFocusForward="@+id/city"
        android:text="****"
        android:focusable="true"
        android:textColor="@android:color/black"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/city"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:nextFocusForward="@+id/address"
        android:text="5145 N"
        android:focusable="true"
        android:textColor="@android:color/black" />

    <TextView
        android:id="@+id/address"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TX 78731"
        android:focusable="true"
        android:textColor="@android:color/black" />

</LinearLayout>

Solution

  • in the textview of your inflator layout just add:

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

    and in parent layout of your inflator i.e in relative layout of inflator add:

    android:descendantFocusability="blocksDescendants"