List adapter vs recycle view adapter

Viewed 7343

Im looking for the difference in using list adapter and recycleview adapter in android. Any different about performance, pros and cons in using them.

3 Answers

ListAdapter is just an extension of RecyclerView.Adapter . Its computes diffs between Lists on a background thread with AsyncListDiff.

You can obviously create a RecyclerView.Adapter to work in same way . Its just ListAdapter already works on this principal out of the box. It defines a contract to force DiffUtil uses hence both of its constructor need a DiffChecker.

Performance will be same if you use ListAdapter or a RecyclerView.Adapter with AsyncDiffChecker. Without async Diff checker ListAdapter's performance will be better.

Recyclerview.Adapter

  • best if the list is static

ListAdapter

  • best if the list is dynamic

List Adapter is extension of RecyclerView.Adapter for presenting List data in a RecyclerView, including computing differences between Lists on a background thread.

It usage DiffUtil 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.

In recycler view using a LiveData is an easy way to provide data to the adapter, with the help of list adapter it isn't required - you can simply call submitList(List) when new lists are available. You can see implementation here.

So in a case of static content you can use RecyclerView.Adapter but in case of dynamic content ListAdapter is preferred.

Related