views:

3489

answers:

2

I've populated a ListActivity from a cursor using SimpleCursorAdapter that starts another activity when one of the list items have been clicked. I'm also using ViewBinder to do some custom transformation of the data.

I want to add a checkbox to each row in the list so I've changed the view and added a CheckBox with gravity right.

Adding the checkbox has removed the ability to click on the items. The onListItemClick method I was overriding in ListActivity is no longer called when you press on a list item. Removing the checkbox fixes this. Why is this?

Also, how can I set up the list so that it continues to perform my required functionality if the main part of the list item is clicked but have additional functionality when the checkbox in the item is checked? Will setting a onCheckedChangedListener work or is the same view instance reused for each item in the list?

+2  A: 

Looks like SimpleCursorAdapter is too primitive for what I wanted to achieve. I've switched to implementing CursorAdapter and returning a new view using the LayoutInflater in my implementation of the newView method.

  public View newView(Context context, Cursor cursor, ViewGroup parent) {
    return LayoutInflater.from(context).inflate(R.layout.alarm_row, parent, false);
  }

In bindView I then set a custom OnClickListener to my main LinearLayout and then another OnCheckedChangeListener to the CheckBox.

For all this to look right I had to set the LinearLayout's background to android's menuitem drawable:

android:background="@android:drawable/menuitem_background"
Tom Martin
+2  A: 

As explained here, the click listener only works if no other view is focusable. Setting your CheckBox to focusable="false" should do the trick:

<CheckBox android:focusable="false" />
Josef