Slide 11
Slide 11 text
@Nullable
ViewHolder tryGetViewHolderForPositionByDeadline(int position, boolean dryRun, long deadlineNs) {
...
ViewHolder holder = null;
// 1) Find by position from scrap/hidden list/cache
if (holder == null) {
holder = getScrapOrHiddenOrCachedHolderForPosition(position, dryRun);
...
}
if (holder == null) {
final int offsetPosition = mAdapterHelper.findPositionOffset(position);
...
final int type = mAdapter.getItemViewType(offsetPosition);
...
if (holder == null) { // fallback to pool
...
holder = getRecycledViewPool().getRecycledView(type);
if (holder != null) {
holder.resetInternal();
...
}
}
if (holder == null) {
...
holder = mAdapter.createViewHolder(RecyclerView.this, type);
...
}
}
...
boolean bound = false;
if (mState.isPreLayout() && holder.isBound()) {
holder.mPreLayoutPosition = position;
} else if (!holder.isBound() || holder.needsUpdate() || holder.isInvalid()) {
final int offsetPosition = mAdapterHelper.findPositionOffset(position);
bound = tryBindViewHolderByDeadline(holder, offsetPosition, position, deadlineNs);
}
...
return holder;
}
RecyclerView.Recycler#tryGetViewHolderForPositionByDeadline
1. view cache 탐색
2. RecycledViewPool 탐색
3. 7번까지 찾지 못했다면 새로운 ViewHolder 생성
(onCreateViewHolder)
4. ViewHolder에 바인딩이 필요하다면 바인딩 실행
(onBindViewHolder)