Recycler View Flashcards
what is a view holder?
he views in the list are represented by view holder objects. These objects are instances of a class you define by extending RecyclerView.ViewHolder. Each view holder is in charge of displaying a single item with a view.
How many view holders are created by the Recycler View?
The RecyclerView creates only as many view holders as are needed to display the on-screen portion of the dynamic content, plus a few extra.
Who is in charge of rebinding new data to the view holders?
The view holder objects are managed by an adapter, which you create by extending RecyclerView.Adapter. The adapter creates view holders as needed. The adapter also binds the view holders to their data
In what function new data is binded to the view holder?
calling the adapter’s onBindViewHolder() method. That method uses the view holder’s position to determine what the contents should be, based on its list position.
I wanna make a recycler view, What’s the first thing I should do?
Add the support library -> Search from Internet!
dependencies {
implementation ‘com.android.support:recyclerview-v7:28.0.0’
}
I have just added my dependency, what’s the next thing for implementing a recycler view?
You can add a recycler view to your layout file:
What kind of Optimization does the recycler view does for us?
This RecyclerView model does a lot of optimization work so you don’t have to:
- When the list is first populated, it creates and binds some view holders on either side of the list. For example, if the view is displaying list positions 0 through 9, the RecyclerView creates and binds those view holders, and might also create and bind the view holder for position 10. That way, if the user scrolls the list, the next element is ready to display.
- As the user scrolls the list, the RecyclerView creates new view holders as necessary. It also saves the view holders which have scrolled off-screen, so they can be reused. If the user switches the direction they were scrolling, the view holders which were scrolled off the screen can be brought right back. On the other hand, if the user keeps scrolling in the same direction, the view holders which have been off-screen the longest can be re-bound to new data. The view holder does not need to be created or have its view inflated; instead, the app just updates the view’s contents to match the new item it was bound to.
- When the displayed items change, you can notify the adapter by calling an appropriate RecyclerView.Adapter.notify…() method. The adapter’s built-in code then rebinds just the affected items.
What objects the activity that has a recyclerView list should have?
private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;
the —- should set its Adapter and it’s —-
- RecyclerView => Yes RcyclerView has an Adapter
2. Layout manager!
What Elements should the class that extends the adapter and serves as an adapter for the recycler view have?
A view Holder Inner Class
onCreateViewHolder
onBindViewHolder
getItemCount() {
The —- should have the DataSet
Adapter