问题
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