我正在尝试将数据从我绑定SQLiteDatabase到ListView.我现在用的SimpleCursorAdapter是填写我的ListView.不幸的是,这似乎不适用于设置CheckBox的checked属性.
这就是我现在这样做的方式; 而不是更改CheckBox的检查状态,适配器正在填充text参数的值,因此该值显示在CheckBox右侧作为文本.
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 }
) );
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
编辑:数据库中的字段当然是boolean类型的,我也尝试将id分配给checked字段以填充值.