I tried all way but always it is referencing the previous one.
mListPreviousData = new ArrayList<>();
for (int i = 0; i < mAddedList.size(); i++) {
mListPreviousData.add(mAddedList.get(i));
}
I tried all way but always it is referencing the previous one.
mListPreviousData = new ArrayList<>();
for (int i = 0; i < mAddedList.size(); i++) {
mListPreviousData.add(mAddedList.get(i));
}
You need to make a deep copy of the underlying objects:
mListPreviousData = new ArrayList<>();
for (int i = 0; i < mAddedList.size(); i++) {
mListPreviousData.add(mAddedList.get(i).clone());
}
Preferably, you implement your own clone()
method.
Edit:
Or do a deep copy of the entire arraylist:
mListPreviousData = (..cast to your type..) mAddedList.clone();
mListPreviousData = new ArrayList<>();
mListPreviousData.addAll(mAddedList);