我在每个视图中有一个带有 checktextview 的列表视图,我的所有项目都通过数据库进行操作,一切正常,但我无法保存列表项目的选中状态,我为每次点击设置了一个可绘制集,但我不知道如何如果我开始另一项活动,请保存它,非常感谢带有代码的答案,谢谢请帮助!
listview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View v, int position,
long id) {
// TODO Auto-generated method stub
CheckedTextView tt = (CheckedTextView) v
.findViewById(R.id.checkedview1);
if (!tt.isChecked()) {
tt.setChecked(true);
tt.setCheckMarkDrawable(R.drawable.checkedbox);
} else {
tt.setChecked(false);
tt.setCheckMarkDrawable(R.drawable.nullbox);
}
}
});
这是我的 listview 和我的 checkedtextview 的 xml
<CheckedTextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/checkedview1"
android:paddingLeft="20dip"
android:paddingRight="20dip"
android:paddingTop="10dip"
android:paddingBottom="10dip"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:checkMark="@drawable/nullbox"
android:textSize = "18sp"
android:textColor="#000000"
android:listSelector="#ef0000"
>
还有我的列表视图
<ListView
android:id="@+id/list1"
android:layout_width="match_parent"
android:layout_height="404dp"
android:cacheColorHint="#ffffff" />
这是我用来加载列表 checklistDB.open() 的适配器;c = checklistDB.getAllTasks();
for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
String task = c.getString(1);
adapter.add(task);
}
checklistDB.close();