[Android] Did you still using notifyDataSetChanged()?

Recyclerview

DiffUtil

  1. areItemsTheSame : Check whether two objects represent the same item. Commonly, check theire id equality. Check First. If this return value is false, list is flicking.
  2. areContentsTheSame : Check whether two items have the same data. If areItemsTheSame return is true, this method is called.
  1. DiffUtil.calculateDiff() : Calculate the list of update that can convert old to new one.
  2. dispatchUpdatesTo(adapter) : Share update event to adapter.
  • You must replace list to new one before calling dispatchUpdatesTo method. Like example, clear(); addAll()

AsyncListDiffer

  • DiffUtil.ItemCallback : Callback for calculating the diff between two non-null items in a list.
  1. submitList() : Pass a new List to the AdapterHelper. Adapter updates will be computed on a background thread.
  2. currentList : Check current list items.

ListAdapter

  1. You don’t need to call getItemCount() override method anymore.
  2. You can call getItem(position).

Whey we need to use ListAdapter?

  • You can update changed items of the list easily.
  • You don’t need to care about thread.
  • Code is simple!

--

--

--

Developer who love travel, beer, natural and music 🧡

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Integrate Google Maps In Android DialogFragment

Implem Search in RecyclerView

From Zero to GDB in Android (Part-1)

Let’s Install a Custom ROM

Nested RecyclerView In Android

Twitter Spinner — Flutter

Given-When-Then Style on Android Development using JUnit5

Sending Firebase Push Notifications via Spring Boot Application — Part 2: Detecting Kotlin…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Thxall92

Thxall92

Developer who love travel, beer, natural and music 🧡

More from Medium

CS 373 Spring 2022: Kyle Kamka

The Importance of React’s setState() Method in Class Components

Namecoin archeology “Gospel according to Matthew”

Han Dynasty, Everything Zhou, and Kung Fu