I am trying to bind data from my SQLiteDatabase to a ListView . I am currently using SimpleCursorAdapter to populate my ListView . Unfortunately, this does not work with setting the CheckBox checked attribute.
This is how I do it now; instead of changing the check state of the CheckBox, the adapter fills the value with a text argument, therefore the value is displayed to the right of the CheckBox as text.
Java:
setListAdapter( new SimpleCursorAdapter( this, R.layout.mylist, data, new String[] { Datenbank.DB_STATE, Datenbank.DB_NAME }, new int[] { R.id.list_checkbox, R.id.list_text } ) );
mylist.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" > <CheckBox android:text="" android:id="@+id/list_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="false" ></CheckBox> <TextView android:text="" android:id="@+id/list_text" android:layout_width="wrap_content" android:layout_height="wrap_content" ></TextView> </LinearLayout>
Edit: The field in the database, of course, is of type boolean, and I also tried to assign an identifier to the field being checked to fill in the value.
android checkbox listview cursor
svens 01 Oct '09 at 18:46 2009-10-01 18:46
source share