将复选框的状态保存在列表中 [英] save the state of checkboxes in a list
问题描述
我有一个带有相应复选框的列表,我想保存它们的状态,以便在应用运行时加载选中项目的列表。我该怎么办?
I have a list with corresponding checkboxes, I would like to save the state of them so I can load the list of checked item when the app runs. How would I do this?
我的onRetain如下:
My onRetain looks like:
public Object onRetainNonConfigurationInstance() {
return planets;
}
其中行星是整个列表。
我已经阅读了SharedPreferences,但似乎无法正常工作:(
I have read up on SharedPreferences but I can't seem to get it working :(
推荐答案
数据库:::
表名:state_checkBox
database::: Table name : state_checkBox
字段
位置:int
状态:布尔值
Fields position : int state : boolean
有关代码,请参见此链接。
for code refer this links..
您只需要在数据库中将状态更新为 true或 false,但是在getview
中,您每次都必须调用查询设置setChecked()复选框
you just have to update the state as "true" or "false" in the database but in getview all time you have to call a query to setChecked() the checkbox
&您必须更新复选框的checkedchangedlistner()上的数据库...
& you hav to update the database on the checkedchangedlistner() of the checkbox...
这篇关于将复选框的状态保存在列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!