clear + addAll vs re-initialise list RecyclerViewAdapter android

ぃ、小莉子 提交于 2019-12-11 16:04:58

问题


What's the different between 1 and 2:

1.

public void updatePostList(ArrayList<Post> updatedPosts) {
   this.postList.clear();
   this.postList.addAll(updatedPosts);
   notifyDataSetChanged();
}

2.

public void updatePostList(ArrayList<Post> updatedPosts) {
   this.postList = updatedPosts;
   notifyDataSetChanged();
}

For me, #1 doesn't work as calling this.postList.clear() clears updatedPosts too instead of just clearing postList and I can't understand why.

来源:https://stackoverflow.com/questions/56454443/clear-addall-vs-re-initialise-list-recyclerviewadapter-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!