I have little trouble with my adapter. After I add new content to my list and refreshing with notifyDataSetChanged
the onClickListener
doesn't work for that new item. After I do click back and go back to the add menu, the item works fine.
So the loading part works perfectly.
The first Adapter with list it do works perfectly. Its pretty much the same code.
In onCreate
function...
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();
}
}
}
}
});