【发布时间】:2012-10-05 21:50:52
【问题描述】:
我正在尝试在此处使用 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"));
}
}
【问题讨论】:
-
如果您收到错误消息,请同时发布。人们没有第二眼。
-
add() 下只有一条红线,错误的详细信息显示“ArrayList
类型中的方法 add (R.string) 不适用于参数 (String )" -
呃,
string和String在 Java 中不是一回事。注意S's。 -
呃@spoike 如果没有聪明的评论,我们本可以做到的。我不知道这一点,这就是我问的原因。并且所有的“字符串”都应该有一个小写的“s”错字。
-
@Far 这是一个提示。检查下面的答案。
标签: java arrays eclipse string split