

While implementing listview, we use an adapter that inserts the items in the list from a source like database query etc. Package import import 7. import 7.util.DiffUtil import 7.widget.RecyclerView import import import import import import import import ListView is a widget that displays a list of vertically scroll-able items. We need an instance of DiffUtil.ItemCallback to be passed into ListAdapter constructor.ItemCallback handles just the second of these, which allows separation of code that indexes into an array or List from the presentation-layer and content specific diffing code. Add the v7 Support Library to gradle build fileĭiffUtil is a utility class that can calculate the difference between two lists and output a list of update operations that converts the first list into the second one.ĭiffUtil.Callback is a Callback class used by DiffUtil while calculating the diff between two lists.ĭiffUtil.Callback serves two roles - list indexing, and item diffing.A class extending RecyclerView.ViewHolder.įiles we need for this app are shown in the image below.Ĭreate new android application keep default options.A class extending DiffUtil.ItemCallback.RecyclerView widget added to the activity layout.

To display items on RecyclerView you need to the following: We will use ListAdapterinstead of the usual RecyclerView.Adapter as shown in a previous post Create a List with RecyclerView.

We will build an app that displays a list of hard-coded instances of class Link in a RecyclerView.

This will help RecyclerView animate changes automatically with less work on the UI thread. ListAdapter uses DiffUtil under the hood to compute list diffs on a background thread. ListAdapter for RecyclerView has been introduced in Revision 27.1.0 Release of Support Library.
