Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Slow rendering best practices
// NOT OK
void onNewEmailsArrivedNotRecommended(List<Email> newEmails) {
emailAdapter.setEmails(newEmails);
emailAdapter.notifyDataSetChanged();
}
// OK
void onNewDataArrivedFastRendering(List<Email> newEmails) {
List<Email> oldEmails = emailAdapter.getEmails();
DiffUtil.DiffResult result = DiffUtil.calculateDiff(new EmailDiffCallback(oldEmails, newEmails));
emailAdapter.setEmails(newEmails);
result.dispatchUpdatesTo(emailAdapter);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.