4

Hello I've already read quite a bit about the CheckBox/ListView problems in Android. So I've tried a number of issues.

To start my layout for a row looks like this.

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <CheckBox 
            android:id="@+id/check" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:focusable="false"
            android:focusableInTouchMode="false" 
            android:text="" /> 
   </LinearLayout>

So then I tried adding this to my ListActivity

 ListView listview = getListView();
 listview.setItemsCanFocus(false);

And then attempted to run it with a breakpoint on onListItemClick, still no hit (running debugging of course).

This is my onListItemClick in case you want to see.

@Override
    protected void onListItemClick(ListView l, View v, int position, long id) {

        // let's find the checkbox we're on.
        CheckBox targetCheckBox = (CheckBox) l.findViewById(R.id.check);

        // ok update the database with the new data. 
        mDbHelper.updateNote(id, !targetCheckBox.isChecked());

        // update the list now.
        showList();

    }

If I then change the Checkbox to CheckTextView, it does work, however I've never done that before, and I'd rather figure out exactly what's wrong here when other people have solved this. Any Thoughts?

Kinglink
  • 819
  • 1
  • 8
  • 14
  • Once you get `onListItemClick()` called, your code is broken. You do not call `findViewById()` on the `ListView` to get your `CheckBox`, you use `findViewById()` on the `View v`, which is the row `View`. – CommonsWare Jun 25 '10 at 00:44
  • Ahh Thanks for that. However my Breakpoint on that line isn't even getting hit so I haven't had a chance to debug that code at all (other than it does get hit with a checktextview). – Kinglink Jun 25 '10 at 20:24

1 Answers1

13

Apparently I was missing

android:clickable="false"

under the Checkbox in addition to

android:focusable="false"

Adding the both lines makes the onListItemClick fire correctly.

Pavya
  • 6,015
  • 4
  • 29
  • 42
Kinglink
  • 819
  • 1
  • 8
  • 14