Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the responsibilities of, and differences between, a RecyclerView Adapter and RecyclerView LayoutManager?

Tags:

I am trying to understand the RecyclerView but I can't understand the difference between the Adapter and LayoutManager.

Can anyone explain it to me?

like image 570
Abd EL Magied Avatar asked Jul 22 '17 22:07

Abd EL Magied


People also ask

What is the purpose of the LayoutManager of the RecyclerView?

A LayoutManager is responsible for measuring and positioning item views within a RecyclerView as well as determining the policy for when to recycle item views that are no longer visible to the user.

What is the relationship between RecyclerView adapter and RecyclerView ViewHolder?

Adapters provide a binding from an app-specific data set to views that are displayed within a RecyclerView . A class that extends ViewHolder that will be used by the adapter.

What is the difference between list adapter and RecyclerView adapter?

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

What is ViewHolder and adapter?

ViewHolder class which caches views associated with the default Preference layouts. A ViewHolder describes an item view and metadata about its place within the RecyclerView. RecyclerView. Adapter implementations should subclass ViewHolder and add fields for caching potentially expensive View. findViewById(int) results.


1 Answers

The adapter is used to create (and bind data to) views that correspond to each item in your dataset.

The layout manager is responsible for the layout of these views.

The adapter doesn't know how the views will be positioned and sized. This means you can swap the layout manager without having to change your adapter code e.g. switching from a LinearLayoutManager to GridLayoutManager.

Check out this answer for a deeper (though still high-level) explanation (scroll past the initial code block to the section about RecyclerView philosophy):

ListView to RecyclerView Migration for CustomView

like image 151
ataulm Avatar answered Sep 20 '22 14:09

ataulm