- RecyclerView makes it easy to efficiently display large sets of data. You supply the data and define how each item looks, and the RecyclerView library dynamically creates the elements when they're needed.
- decide what the list or grid is going to look like. Ordinarily you'll be able to use one of the RecyclerView library's standard layout managers.
- Design how each element in the list is going to look and behave. Based on this design, extend the
ViewHolderclass. Your version ofViewHolderprovides all the functionality for your list items. Your view holder is a wrapper around aView, and that view is managed by RecyclerView. - Define the
Adapterthat associates your data with theViewHolderviews.
- The RecyclerView library provides three layout managers, which handle the most common layout situations:
LinearLayoutManagerarranges the items in a one-dimensional list.GridLayoutManagerarranges all items in a two-dimensional gridStaggeredGridLayoutManageris similar to GridLayoutManager, but it does not require that items in a row have the same height (for vertical grids) or items in the same column have the same width (for horizontal grids).
- When you define your adapter, you need to override three key methods
onCreateViewHolder():RecyclerViewcalls this method whenever it needs to create a newViewHolder. The method creates and initializes the ViewHolder and its associated View, but does not fill in the view's contents—theViewHolderhas not yet been bound to specific data.onBindViewHolder():RecyclerViewcalls this method to associate aViewHolderwith data. The method fetches the appropriate data and uses the data to fill in the view holder's layout.getItemCount(): RecyclerView calls this method to get the size of the data set.