我正在尝试在这里使用 SharedPreferences 做一个教程Simple Multiple Selection Checkboxes它似乎我的所有其他代码都很好,但我收到一条参数不适用的错误消息。我猜在本教程中他们正在尝试向数组添加一些值。这是我尝试过的,但我仍然得到一个错误。
private void LoadSelections() {
// if the selections were previously saved load them
SharedPreferences settingsActivity = getPreferences(MODE_PRIVATE);
if (settingsActivity.contains(SETTING_TODOLIST)) {
String savedItems = settingsActivity
.getString(SETTING_TODOLIST, "");
this.selectedItems.addAll(Arrays.asList(savedItems.split(",")));
int count = this.mainListView.getAdapter().getCount();
for (int i = 0; i < count; i++) {
String currentItem = (String) this.mainListView.getAdapter()
.getItem(i);
if (this.selectedItems.contains(currentItem)) {
this.mainListView.setItemChecked(i, true);
}
}
}
}
private ArrayList<string> PrepareListFromXml() {
ArrayList<string> cheeseItems = new ArrayList<string>();
XmlResourceParser ingredientsXML = getResources().getXml(R.xml.ingredients);
int eventType = -1;
while (eventType != XmlResourceParser.END_DOCUMENT) {
if (eventType == XmlResourceParser.START_TAG) {
String strNode = ingredientsXML.getName();
if (strNode.equals("item")) {
cheeseItems.add(ingredientsXML.getAttributeValue(null,"title"));
}
}