My ListView
is using an extension of BaseAdapter
, I can not get it to refresh properly. When I refresh, it appears that the old data draws on top
You don't have to create a new adapter to update your ListView's contents. Simply store your Adapter in a field and update your list with the following code:
mAdapter.setList(yourNewList);
mAdapter.notifyDataSetChanged();
To clarify that, your Activity should look like that:
private YourAdapter mAdapter;
protected void onCreate(...) {
...
mAdapter = new YourAdapter(this);
setListAdapter(mAdapter);
updateData();
}
private void updateData() {
List<Data> newData = getYourNewData();
mAdapter.setList(yourNewList);
mAdapter.notifyDataSetChanged();
}
I'm doing the same thing using invalidateViews() and that works for me. If you want it to invalidate immediately you could try calling postInvalidate after calling invalidateViews.
Another easy way:
//In your ListViewActivity:
public void refreshListView() {
listAdapter = new ListAdapter(this);
setListAdapter(listAdapter);
}