Android ListView with Checkbox and all clickable

codie4711 picture codie4711 · Mar 24, 2011 · Viewed 110.2k times · Source

Possible Duplicate:
Android: Binding data from a database to a CheckBox in a ListView?

i want to use a ListView with the items having following layout

------------------------- 
 [CB]    TV            TV
-------------------------

CB is a checkbox and TV is a Textview.

Now i've read somewhere that you can't have clickable items in a ListView. If you have some then you won't be able to click on the ListItems. But if I look at the GoogleMail app, this is possible. I can mark several messages with the checkbox (and then select an action for them) or i can click on the ListItem (or scroll with the dpad) to get to another screen. Does someone has code/example how this is possible?

Answer

PacificSky picture PacificSky · May 22, 2012

Set the CheckBox as focusable="false" in your XML layout. Otherwise it will steal click events from the list view.

Of course, if you do this, you need to manually handle marking the CheckBox as checked/unchecked if the list item is clicked instead of the CheckBox, but you probably want that anyway.