您好我是Android开发新手, 如何在Android SDK中显示带有复选框的自定义列表视图。我需要在不需要选择之前选择复选框。
例如我有一个favarote视图,因为我选择了一些以前在我必须去那个视图时应该显示为选中的项目。
请任何人帮助我。
提前致谢
答案 0 :(得分:0)
private void SaveSelections() {
// save the selections in the shared preference in private mode for the
// user
SharedPreferences settingsActivity = getPreferences(MODE_PRIVATE);
SharedPreferences.Editor prefEditor = settingsActivity.edit();
savedNames = getSavedItems();
prefEditor.putString(SETTING_TODOLIST, savedNames);
prefEditor.commit();
}
private String getSavedItems() {
String savedNames = "";
int count = this.listView.getAdapter().getCount();
for (int i = 0; i < count; i++) {
if (FPhoneListCheckboxAES.phonelist.get(i).getChecked() == true) {
if (savedNames.length() > 0) {
savedNames += ","
+ FPhoneListCheckboxAES.phonelist.get(i).getname();
savedPhoneno += ","
+ FPhoneListCheckboxAES.phonelist.get(i).getphoneNo();
} else {
savedNames += FPhoneListCheckboxAES.phonelist.get(i).getname();
savedPhoneno += FPhoneListCheckboxAES.phonelist.get(i)
.getphoneNo();
}
}
}
return savedNames;
}
检查链接,这将有很多帮助
http://appfulcrum.com/2010/09/12/listview-example-3-simple-multiple-selection-checkboxes/