A Lesson by Mike Wolfson
DiffUtil is a new feature of the AppCompat library that makes it easier to understand how to animate complex data changes in a RecyclerView. Previously, if you wanted to use animations it was necessary to know details about the changes in your data, so you could chose the correct notify methods. You can use this tool to figure out the details of your changes, and it will apply the correct animations automatically.
I will show you how to create a custom
DiffUtil.Callback, which is class used by the system to compare objects in a list. You will customize this class, based on your data and use case, then the system will use this class to automatically figure out the changes in your list, and apply the correct animations as appropriate.
Code for the Lesson
Pro members: Log in to view the code for this lesson!
Lessons in this course
- RecyclerView – Introduction
- RecyclerView – Creating a Vertical List
- RecyclerView – Reverse ordering and Horizontal list
- RecyclerView – GridLayoutManager and SpanSizeLookup
- RecyclerView: Using StaggeredGridLayoutManager for Variably Sized Content
- RecyclerView: Using ItemDecoration to add simple dividers and custom dividers
- RecyclerView: ItemDecoration Advanced Usage and Customization
- RecyclerView: Drag & Drop and Swipe to Dismiss using ItemTouchHelper
- RecyclerView: Animate Content Changes
- RecyclerView: Animate complex content changes with DiffUtil