# RecyclerView.ViewCacheExtension

# RecyclerView.ViewCacheExtension

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.ViewCacheExtension)  
Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ViewCacheExtension "View this page in Java")

<br />

```
abstract class RecyclerView.ViewCacheExtension
```

<br />

*** ** * ** ***

ViewCacheExtension is a helper class to provide an additional layer of view caching that can be controlled by the developer.

When[getViewForPosition](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Recycler#getViewForPosition(int))is called, Recycler checks attached scrap and first level cache to find a matching View. If it cannot find a suitable View, Recycler will call the[getViewForPositionAndType](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewCacheExtension#getViewForPositionAndType(androidx.recyclerview.widget.RecyclerView.Recycler,int,int))before checking[RecycledViewPool](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.RecycledViewPool).

Note that, Recycler never sends Views to this method to be cached. It is developers responsibility to decide whether they want to keep their Views in this custom cache or let the default recycling policy handle it.

## Summary

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

|                                 ### Public functions                                 |
|--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `abstract `[View](https://developer.android.com/reference/android/view/View.html)`?` | [getViewForPositionAndType](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewCacheExtension#getViewForPositionAndType(androidx.recyclerview.widget.RecyclerView.Recycler,int,int))`(` ` recycler: `[RecyclerView.Recycler](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Recycler)`,` ` position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` type: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) `)` Returns a View that can be binded to the given Adapter position. |

## Public constructors

### ViewCacheExtension

Added in 1.0.0  

```
ViewCacheExtension()
```  

## Public functions

### getViewForPositionAndType

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

```
abstract fun getViewForPositionAndType(
    recycler: RecyclerView.Recycler,
    position: Int,
    type: Int
): View?
```

Returns a View that can be binded to the given Adapter position.

This method should**not** create a new View. Instead, it is expected to return an already created View that can be re-used for the given type and position. If the View is marked as ignored, it should first call[stopIgnoringView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.LayoutManager#stopIgnoringView(android.view.View))before returning the View.

RecyclerView will re-bind the returned View to the position if necessary.  

|                                                               Parameters                                                               |
|----------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------|
| `recycler: `[RecyclerView.Recycler](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Recycler) | The Recycler that can be used to bind the View |
| `position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                | The adapter position                           |
| `type: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                    | The type of the View, defined by adapter       |

|                                  Returns                                  |
|---------------------------------------------------------------------------|----------------------------------------------------------------------------------|
| [View](https://developer.android.com/reference/android/view/View.html)`?` | A View that is bound to the given position or NULL if there is no View to re-use |

|                                                                      See also                                                                      |
|----------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [ignoreView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.LayoutManager#ignoreView(android.view.View)) |   |