../recyclerview-note
By VickyeeRecyclerView Note
References
When to get the View and try to get it from cache? →
Recycler.getViewForPosition()
How to try getting View from cache?
There are some simple caches in eg
LinearLayoutManager.mScrapList
.The core cache of a RecyclerView is Recycler. See
Recycler.getViewForPosition
. Here is the priority in it (Recycler.tryGetViewHolderForPositionByDeadline
) :// 0, by position, then id // from scrap - mChangedScrap getChangedScrapViewForPosition(); // 1, by position // from scrap - mAttachedScrap // then hidden - mHiddenViews // then cache - mCachedViews getScrapOrHiddenOrCachedHolderForPosition(); // 2, by id // from scrap - mAttachedScrap // then cache - mCachedViews getScrapOrCachedViewForId(); // 3 (ViewCacheExtension) mViewCacheExtension.getViewForPositionAndType(); // 4 getRecycledViewPool().getRecycledView(type); // 5, create one mAdapter.createViewHolder();
After getting the ViewHolder instance, check for binding and use
tryBindViewHolderByDeadline
to bind. Then it is ok to return the ViewHolder.