Skip to content

Instantly share code, notes, and snippets.

@iammert
Created August 20, 2016 16:10
Show Gist options
  • Save iammert/16c4006221f9815ed2cf2a3c0cc90627 to your computer and use it in GitHub Desktop.
Save iammert/16c4006221f9815ed2cf2a3c0cc90627 to your computer and use it in GitHub Desktop.
public class MyDiffCallback extends DiffUtil.Callback{
List<Person> oldPersons;
List<Person> newPersons;
public MyDiffCallback(List<Person> newPersons, List<Person> oldPersons) {
this.newPersons = newPersons;
this.oldPersons = oldPersons;
}
@Override
public int getOldListSize() {
return oldPersons.size();
}
@Override
public int getNewListSize() {
return newPersons.size();
}
@Override
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
return oldPersons.get(oldItemPosition).id == newPersons.get(newItemPosition).id;
}
@Override
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
return oldPersons.get(oldItemPosition).equals(newPersons.get(newItemPosition));
}
@Nullable
@Override
public Object getChangePayload(int oldItemPosition, int newItemPosition) {
//you can return particular field for changed item.
return super.getChangePayload(oldItemPosition, newItemPosition);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment