Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List adapter vs recycle view adapter

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

like image 661
Đàm Tùng Avatar asked Mar 05 '21 02:03

Đàm Tùng


People also ask

How to set data to adapter in recyclerview?

After that generally, we provide a way to set data to adapter by adding a method like setList () and then in the method we assign a new list and then we call notifyDataSetChanged () to update RecyclerView. But that’s not it. The method notifyDataSetChanged () refreshes whole list.

What is the difference between listview and recyclerview viewholder?

The ViewHolder pattern is entirely optional in ListView, but it’s baked into RecyclerView. ListView only supports vertical scrolling, but RecyclerView isn’t limited to vertically scrolling lists. Show activity on this post.

How do I get data from a list adapter?

ListAdapter gets data using a method called submitList (), which submits a list to be diffed against the current list and displayed. This means you no longer have to override getItemCount () because ListAdapter manages the list. In the Activity class, call submitList () on the Adapter and pass in the data list.

How to add a divider to a recyclerview list?

For example the RecyclerView list by default has no dividers between rows — it’s consistent with the Material Design guidelines. However if we want to add divider for some reason, we can use DividerItemDecoration and add it to the RecyclerView.


2 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.

like image 123
ADM Avatar answered Sep 19 '22 01:09

ADM


Recyclerview.Adapter

  • best if the list is static

ListAdapter

  • best if the list is dynamic
like image 23
Jasper Calapini Avatar answered Sep 18 '22 01:09

Jasper Calapini