How to clear a ListView in Android?
I created a customized ListView with an image and two TextViews. 开发者_运维百科At the moment, when the list is called more than once, the data is appended to the end of the list.
Is there a way to clear the listview so that the new data is again at the top of the listView?
You probably want to issue a .clear()
on your adapter.
Note that this depends on the Adapter you use, you may not be able to do this. SimpleAdapter is used for static data, thus it can't be updated after creation.
PS. not all Adapters have a clear() method. ArrayAdapter does, but ListAdapter or SimpleAdapter don't
Initialise the adapter again with the constructor and then set to listview listView.setAdapter(new ListAdapter());
精彩评论