Skip to content

Instantly share code, notes, and snippets.

@shaon2016
Created January 28, 2018 04:34
Show Gist options
  • Save shaon2016/1abcf46182d9afa0f28f806c10b8738c to your computer and use it in GitHub Desktop.
Save shaon2016/1abcf46182d9afa0f28f806c10b8738c to your computer and use it in GitHub Desktop.
This code ensures that duplicate data will not be in rv list.
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