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?
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.
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.
List Adapter is extension of RecyclerView. Adapter for presenting List data in a RecyclerView, including computing differences between Lists on a background thread.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With