I'm trying to assign a global variable's data and alter the local variable's data, but then when I change the local variable's structure, the global variable gets changed as well.
private void remove(Message M) {
int p = list.lastIndexOf(M);
List<Message> x = list;
list.remove(p);
indexedMessages.remove(M.getMessageid());
notifyItemRemoved(p);
notifyItemRangeChanged(p, list.size());
// Removing the following items from "x" also causes the elements to be removed from recycleView.
x.remove(0);
x.remove(x.size() - 1);
}
Two things I don't understand :
- Why is "x" affecting "list"
- And why is "notifyItemRemoved" triggered again.
Anyway, on the original "list" (private List list), the first & last items are just placeholders. When an item is removed from this list, I want to store a new copy of that list without the placeholder.
The placeholders get added every time the adapter is created.