Android: how to refresh ListView contents?

后端 未结 9 942
渐次进展
渐次进展 2020-11-28 04:58

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

9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 05:37

    I think refilling the same adapter with different data would be more or most better technique. Put this method in your Adapter class with right argument (the data list you want to display as names in my case) Call this where u update the data of list with updated list (names in my case)

    public void refill(ArrayList names) {
        list.clear();
        list.addAll(names);
        list.notifyDataSetChanged();
    }
    

    If you change the adapter or set the adapter again and again on when the list updates, then force close error would surely cause problems at some point. (Error:List data been updated but adapter doesn't notify the List View)

提交回复
热议问题