I have a Listview that looks like the following:
checkbox:textview {0 .. n}
I have a OnCheckChangedListener that listens for checkbox changes (checkbox has focusable set to false as recommended by http://www.mousetech.com/blog/?p=74).
The behaviour that I am looking for is that users can click the checkbox to set its state, and they can click on the listview item to get a description.
Currently, checkbox state is saved properly and if you click on an item, then it shows a description. However, if you first change a state and then click to get the description, the checkbox reverts to a prior state. In fact all checkboxes revert back to a prior state.
Anyone know how i can get this working?
Thanks.
*****EDIT********
SimpleCursorAdapter adapter =
new SimpleCursorAdapter(this,
R.layout.listview_item,
cursor,
new String[] {MyContentColumns.NAME, MyContentColumns.MyBoolean },
new int[] {R.id.listview_item_title,R.id.listview_item_myBoolean });
adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
@Override
public boolean setViewValue(View view, Cursor cursor,int columnIndex) {
String c_name = cursor.getColumnName(columnIndex);
if (c_name.equals(MyContentColumns.NAME)) {
// set up name and description of listview
MyContent v = mycontent.getMyContent(cursor.getString(columnIndex));
if (view instanceof TextView) {
TextView tv = (TextView) view;
if (tv.getId() == R.id.listview_item_title) {
tv.setText(v.getLongName());
}
}
return true;
} else if (c_name.equals(MyContentColumns.MyBoolean)) {
// if myBoolean == 0, box is checked
// if myBoolean == 1, box is unchecked
int myBoolean = cursor.getInt((cursor.getColumnIndex(MyContentColumns.MyBoolean)));
final String myCont_name = cursor.getString(cursor.getColumnIndex(MyContentColumns.NAME));
final String myCont_cid = cursor.getString(cursor.getColumnIndex(MyContentColumns.CONTENT_ID));
final long c_id = cursor.getLong(cursor.getColumnIndex(MyContentColumns._ID));
if (view instanceof CheckBox) {
((CheckBox) view).setChecked(myBoolean == 1);
((CheckBox) view)
.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
ContentValues values = new ContentValues();
values.put(MyContentColumns.MyBoolean,isChecked ? 1 : 0);
int rows = getContentResolver()
.update(
ContentUris.withAppendedId(Uri.withAppendedPath(MyContentColumns.CONTENT_URI,"mycontent"),c_id),
values,
null,
null);
if ( rows == 0) {
Logger.wLog(String
.format("Couldn't update values for %s into db for content %d",
myCont_name, myCont_cid));
}
}
});
}
return true;
}
return false;
}
});
So it seems that clicking on one list item causes the other list items to also get clicked... so values revert and my states become inconsistent... ideas? thanks.