
Retrofit will help us make network calls to the API. In this step, we will create a new project, you can refer to the image below for guidance.Īfter creating the project, we will add some dependencies to our app-level build Gradle. Then display them in a RecyclerView and add a click listener to handle clicks on each row. While the second checks if the data between the two objects is the same.ĭiffUtil makes it possible for ListAdapter to change the items in the list. The first method checks if the two objects are the same (for example, based on ids). We override two of its methods areItemsTheSame(oldItem: Pojo, newItem: Pojo) and areContentsTheSame(oldItem: Pojo, newItem: Pojo). This class removes the need to call the notifyDataSetChanged() method. What is a DiffUtil?Īccording to the official documentation: DiffUtil is a utility class that calculates the difference between two lists and outputs a list of update operations that converts the first list into the second one. It handles the addition and removal of items without the need to redraw the entire view.

You can use submitList(POJO) when new data is available. While using a LiveData, a ListAdapter provides an easy way to provide data to the adapter. What is a ListAdapter?Īccording to the official documentation: A ListAdapter is a RecyclerView.Adapter base class for presenting List data in a RecyclerView, including computing diffs between Lists on a background thread. If it is your first time creating a RecyclerView you can take a look at this article.

The RecyclerView class supports the display of a collection of data.

