I have a Listview that looks like this:
: textview {0 .. n}
I have an OnCheckChangedListener that listens for flag changes (the flag is set to focus with the false value set, as recommended by http://www.mousetech.com/blog/?p=74 ).
The behavior I'm looking for is that users can check the box to set its state, and they can click on the list item to get a description.
Currently, the state of the checkbox is saved correctly, and if you click on an item, it will show a description. However, if you first change the state and then click to get a description, the checkbox returns to the previous state. Virtually all flags are returned to their previous state.
Does anyone know how I can make this work?
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 get clicked too ... so the values are returned and my states become inconsistent ... ideas? thanks.
android checkbox listview
ekawas
source share