I am developing a simple Android app which creates a ListView with a checkbox as follows
listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice,results);
this.setListAdapter(listAdapter);
ListView lv = getListView();
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
lv.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
CheckedTextView check = (CheckedTextView)view;
//The below code needed for running on AVD version 4.2
if(check.isChecked()) {
// Checkbox checked do something
}
else {
// Not checked. Do something
}
/* Exact opposite need on Samsung phone running 2.3.6
if(!check.isChecked()) {
// Checkbox checked do something
}
else {
// Not checked. DO something
} */
This is truly weird. How will the app ever be compatible with both version when they require completely opposite checks?
Please let me know how I can handle this. Any help will be appreciated.
i know the problem, on newer frameworks the
onItemClickcall before the checkd attribute of the checkbox changed!i check the checked state of my checkboxes in after item clicking (e.g. on activity close or save button click).
look at
list.getCheckedItemPositions()… it will return aSparseBooleanArrayyou can use!EDIT: example