If for any reason you're using ArrayAdapter to feed your ListView on Android you may be struggling with the fact that whatever you do - executing notifyOnDataSetChanged doesn't result in the corresponding ListView getting refreshed. There is one simple solution for this (and no, I am not talking about one that I saw on one forum where it was suggested to recreate the ArrayAdapter, which on a first glance may be a good idea at least until you're happy with the list jumping every time to the top).
So what you need to do to have your ListView updated is:
1. Either execute
arrayAdapter.remove(itemToRemove); // if you want to delete item from the list
or
arrayAdapter.add(itemToAdd); // if you want to add an item to the list
or
2. Execute
arrayAdapter.clear(); // get rid of all elements arrayAdapter.addAdd(listOfItems); // add them back to the list
Both work just fine.
Comments
Post a Comment