Android APIs
public final class

RecyclerView.Recycler

extends Object
java.lang.Object
   ↳ android.support.v7.widget.RecyclerView.Recycler

Class Overview

A Recycler is responsible for managing scrapped or detached item views for reuse.

A "scrapped" view is a view that is still attached to its parent RecyclerView but that has been marked for removal or reuse.

Typical use of a Recycler by a RecyclerView.LayoutManager will be to obtain views for an adapter's data set representing the data at a given position or item ID. If the view to be reused is considered "dirty" the adapter will be asked to rebind it. If not, the view can be quickly reused by the LayoutManager with no further work. Clean views that have not requested layout may be repositioned by a LayoutManager without remeasurement.

Summary

Public Constructors
RecyclerView.Recycler()
Public Methods
void clear()
Clear scrap views out of this recycler.
List<RecyclerView.ViewHolder> getScrapList()
Returns an unmodifiable list of ViewHolders that are currently in the scrap list.
View getViewForPosition(int position)
Obtain a view initialized for the given position.
void recycleView(View view)
Recycle a detached view.
void setViewCacheSize(int viewCount)
Set the maximum number of detached, valid views we should retain for later use.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public RecyclerView.Recycler ()

Public Methods

public void clear ()

Clear scrap views out of this recycler. Detached views contained within a recycled view pool will remain.

public List<RecyclerView.ViewHolder> getScrapList ()

Returns an unmodifiable list of ViewHolders that are currently in the scrap list.

Returns
  • List of ViewHolders in the scrap list.

public View getViewForPosition (int position)

Obtain a view initialized for the given position.

This method should be used by RecyclerView.LayoutManager implementations to obtain views to represent data from an RecyclerView.Adapter.

The Recycler may reuse a scrap or detached view from a shared pool if one is available for the correct view type. If the adapter has not indicated that the data at the given position has changed, the Recycler will attempt to hand back a scrap view that was previously initialized for that data without rebinding.

Parameters
position Position to obtain a view for
Returns
  • A view representing the data at position from adapter

public void recycleView (View view)

Recycle a detached view. The specified view will be added to a pool of views for later rebinding and reuse.

A view must be fully detached before it may be recycled.

Parameters
view Removed view for recycling

public void setViewCacheSize (int viewCount)

Set the maximum number of detached, valid views we should retain for later use.

Parameters
viewCount Number of views to keep before sending views to the shared pool