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.
updatePostList
method is inside theCustomRecyclerViewAdapter
. TheupdatedPosts
list is sent to this method from theActivity
. – Seleucialist
object. The Second point represents dereferencing and referencing thelist
fromActivity
– Fitzsimmonsthis.postList.clear()
clearupdatedPosts
too instead of just clearingpostList
. – Seleucia