# RecyclerView.RecycledViewPool

Artifact: [androidx.recyclerview:recyclerview](https://developer.android.com/jetpack/androidx/releases/recyclerview) [View Source](https://cs.android.com/search?q=file:androidx/recyclerview/widget/RecyclerView.java+class:androidx.recyclerview.widget.RecyclerView.RecycledViewPool) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

*** ** * ** ***


```
public class RecyclerView.RecycledViewPool
```

<br />

*** ** * ** ***

RecycledViewPool lets you share Views between multiple RecyclerViews.

If you want to recycle views across RecyclerViews, create an instance of RecycledViewPool and use `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView#setRecycledViewPool(androidx.recyclerview.widget.RecyclerView.RecycledViewPool)`.

RecyclerView automatically creates a pool for itself if you don't provide one.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.RecycledViewPool#RecycledViewPool()()` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.RecycledViewPool#clear()()` Discard all ViewHolders. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ViewHolder` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.RecycledViewPool#getRecycledView(int)(int viewType)` Acquire a ViewHolder of the specified type from the pool, or `null` if none are present. |
| `int` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.RecycledViewPool#getRecycledViewCount(int)(int viewType)` Returns the current number of Views held by the RecycledViewPool of the given view type. |
| `void` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.RecycledViewPool#putRecycledView(androidx.recyclerview.widget.RecyclerView.ViewHolder)(https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ViewHolder scrap)` Add a scrap ViewHolder to the pool. |
| `void` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.RecycledViewPool#setMaxRecycledViews(int,int)(int viewType, int max)` Sets the maximum number of ViewHolders to hold in the pool before discarding. |

## Public constructors

### RecycledViewPool

Added in 1.0.0

```
public RecycledViewPool()
```

## Public methods

### clear

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
public void clear()
```

Discard all ViewHolders.

### getRecycledView

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
public @Nullable RecyclerView.ViewHolder getRecycledView(int viewType)
```

Acquire a ViewHolder of the specified type from the pool, or `null` if none are present.

| Parameters |
|---|---|
| `int viewType` | ViewHolder type. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ViewHolder` | ViewHolder of the specified type acquired from the pool, or `null` if none are present. |

### getRecycledViewCount

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
public int getRecycledViewCount(int viewType)
```

Returns the current number of Views held by the RecycledViewPool of the given view type.

### putRecycledView

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
public void putRecycledView(RecyclerView.ViewHolder scrap)
```

Add a scrap ViewHolder to the pool.

If the pool is already full for that ViewHolder's type, it will be immediately discarded.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ViewHolder scrap` | ViewHolder to be added to the pool. |

### setMaxRecycledViews

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
public void setMaxRecycledViews(int viewType, int max)
```

Sets the maximum number of ViewHolders to hold in the pool before discarding.

| Parameters |
|---|---|
| `int viewType` | ViewHolder Type |
| `int max` | Maximum number |