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.

2
  • Do you use focusable widgets within your list item's layout? Like i.e. buttons? Commented Apr 13, 2011 at 17:06
  • I'm just using TextViews and a Checkbox in each row, structured with LinearLayouts. Commented Apr 13, 2011 at 20:19

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

2 Comments

I had to also set android:clickable="false" on the checkbox item in the xml
Was uber frustrated over this.. +10 and (10x) ;) The simplest things, eh?
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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.