adapter.notifyDataSetChanged()不起作用的解决

来源:互联网 发布:任务提醒软件 编辑:程序博客网 时间:2024/06/06 12:47
adapter.notifyDataSetChanged()不起作用的解决
eg:
private CommuFriendValidateAdapter validateAdapter = null;
private List<FriendValidateListItem> friendList = null;
friendList = new ArrayList<FriendValidateListItem>();

adapter = new CommuFriendValidateAdapter(

getApplicationContext(), friendList);

friendValidateListView.setAdapter(validateAdapter);


如果有了新的内容替换adapter内容:

friendList.clear();

friendList = friendList2;(自定义的List内容)

adapter.notifyDataSetChanged();

在当前情况下adapter.notifyDataSetChanged()不起作用

因为:

friendList = friendList2;此时friendList相当于重新创建了对象,和adapter中的对象不一样了就不可以更新了

解决方案:

friendList.clear();

friendList.addAll(friendList2);

adapter.notifyDataSetChanged();

0 0
原创粉丝点击