Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a checkbox with a false focusable, still prevents listview clicks

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?

like image 647
Kinglink Avatar asked Dec 12 '22 21:12

Kinglink


1 Answers

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.

like image 63
Kinglink Avatar answered Dec 28 '22 23:12

Kinglink