The
RecyclerView is an
advanced and flexible version of ListView.
In the RecyclerView model, several different components work together to display your data.
The visible part on the screen is the RecyclerView [C], which is added to the layout as a container that holds all the parts together. RecyclerView fills itself with views provided by a "Layout manager".
The views in the list are represented by "Viewholder" objects.
The RecyclerView creates only as many Viewholder as are needed to display the on-screen portion of the dynamic content, plus a few additional ones. As the user scrolls through the list, RecyclerView takes the off-screen views and links them back to the data scrolling on the screen.
The Viewholder objects are managed using an "Adapter".
If required, the adapter creates a Viewholder. The adapter also binds the Viewholders to their data. This is done by assigning the Viewholder to a position and calling the onBindViewHolder() method of the adapter. This method uses the position of the view holder to determine what the content should be based on its list position.
This RecyclerView model does a lot of optimization work so you don't have to.
When the list is filled for the first time, it creates and binds some viewholders on both sides of the list. For example, if the view displays list positions 0 through 9, RecyclerView creates and binds these viewholders and can also create and bind the viewholders for position 10. So when the user scrolls through the list, the next item is ready for display.
As the user scrolls through the list, the RecyclerView creates new Viewholder as needed. It also stores the view holders that are scrolled in the off-screen area so that they can be reused.
If the user changes the direction in which he scrolled, the view holders scrolled from the screen can be returned. If, on the other hand, the user scrolls in the same direction over and over, the view holders that have been the longest away from the screen can be reattached to new data.
If the data of the displayed elements changes, the adapter is simply notified by calling a corresponding method ...notify...(). The adapter's built-in code then merges the affected elements.