2

I have made a custom ArrayAdapter for a ListView, in order to customize the rows of the list with some elements.

The problem I have is that I cannot select an item, nothing happens when I click. Is it something I have to implement in my custom ArrayAdapter? It only has a constructor and a getView method. When I instantiate my list and implement the onListItemClick, it is ignored, so I think it is something to do with my custom adapter... I have researched through examples but I have found nothing.

What should I do?

EDIT: In each row I'm using a Checkbox, and a LinearLayout that contains TextViews. This LinearLayout is the one that should be selectable.

David Morales
  • 17,816
  • 12
  • 77
  • 105

2 Answers2

6

I believe the issue is Android doesn't allow you to select list items that have elements on them that are focusable.

Set your checkbox in lisview as "Not focusable".

Refer this for details:

android:focusable="false"

Android custom ListView unable to click on items

<checkbox>.setFocusable(false)

http://groups.google.com/group/android-developers/browse_thread/thread/dc070331341ef34/fa6d4356118a1f0d?lnk=gst&q=button+listview+clicks#fa6d4356118a1f0d

Community
  • 1
  • 1
Priyank
  • 10,503
  • 2
  • 27
  • 25
1

I have struggled all DAY with this issue! This is what you layout/xml should look like for your listitem:

This lines should be on all TextViews and other components you are using:

android:focusable="false"
android:clickable="false"/> 

My layout.xml for listitem:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent">    

    <LinearLayout
    android:orientation="vertical"
    android:layout_width="0dip" 
    android:layout_weight="1"
    android:layout_height="fill_parent">

        <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textWhiteTheme" 
        style="@style/list_item_wh"
        android:focusable="false"
        android:clickable="false"/>        

    </LinearLayout>
</LinearLayout>