Created
January 28, 2018 04:34
-
-
Save shaon2016/1abcf46182d9afa0f28f806c10b8738c to your computer and use it in GitHub Desktop.
This code ensures that duplicate data will not be in rv list.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void addAll(ArrayList<Inventory> newList) { | |
// Lg.i(TAG, "Adding all: Current count=" + c + ", \nNew count=" + newList.size()); | |
//Previous List of Recycler View | |
List<Inventory> itemList = this.itemList; | |
for (Inventory iv : newList) { | |
boolean exists = false; | |
// id of new list | |
int id = iv.getId(); | |
for (Inventory ivOld : itemList) | |
// checking new id with old id | |
if (id == ivOld.getId()) { | |
// if exists then don't need to add | |
exists = true; | |
break; | |
} | |
if (!exists) { | |
// if not exists, then we are adding it to the rv list | |
this.itemList.add(iv); | |
notifyItemInserted(this.itemList.size() - 1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment