我的适配器没什么问题。在我将新内容添加到我的列表并使用notifyDataSetChanged
进行刷新后,onClickListener
对该新项目无效。点击后退回到添加菜单后,该项目工作正常。
因此装载部件工作正常。
带有列表的第一个适配器可以很好地工作。它几乎是相同的代码。
在onCreate
函数中......
Button addContent = (Button)findViewById(R.id.addContent_button);
final ListView myList = (ListView)findViewById(R.id.mainMenuList);
final boolean deleteMode = false;
String[] liegenSchaften = new String[] {};
final List<String> content = new ArrayList<String>(Arrays.asList(liegenSchaften));
final ArrayAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, content);
myList.setAdapter(adapter);
//load the Save Data
Map<String, ?> map = getSaveMap();
//add exists data to list
for (Map.Entry<String, ?> entry : map.entrySet()) {
content.add(entry.getValue().toString());
}
// Update adapter, this works fine!
adapter.notifyDataSetChanged();
addContent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
content.add(editedText.getText().toString());
/* This adapter dont Update the new Content, the item display and is not clickeble */
adapter.notifyDataSetChanged();
editor.putString(editedText.getText().toString(), editedText.getText().toString());
editor.commit();
}
});
myList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
//load the Save Data
Map<String, ?> map = getSaveMap();
Object obj = myList.getAdapter().getItem(position);
String value = obj.toString();
//add exists data to list
for (Map.Entry<String, ?> entry : map.entrySet()) {
if(entry.getValue().toString() == value) {
if(deleteMode) {
editor.remove(value);
editor.commit();
content.remove(position);
adapter.notifyDataSetChanged();
} else {
selectedContent = entry.getValue().toString();
addMessage.setText(entry.getValue().toString() + " Wurde gewählt.");
addMessage.show();
}
}
}
}
});
答案 0 :(得分:0)
我发现了问题:
查询错误。现在我使用了equals,ArrayAdapter
很漂亮!
if(entry.getValue().toString().equals(value))