Android ListView with Checkbox and all clickable [duplicate] Android ListView with Checkbox and all clickable [duplicate] android android

Android ListView with Checkbox and all clickable [duplicate]


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.


Set the listview adapter to "simple_list_item_multiple_choice"

ArrayAdapter<String> adapter;List<String> values; // put values in this//Put in listviewadapter = new ArrayAdapter<UserProfile>(this,android.R.layout.simple_list_item_multiple_choice, values);setListAdapter(adapter);    


holder.checkbox.setTag(row_id);

and

holder.checkbox.setOnClickListener( new OnClickListener() {                @Override                public void onClick(View v) {                    CheckBox c = (CheckBox) v;                    int row_id = (Integer) v.getTag();                    checkboxes.put(row_id, c.isChecked());                }        });