RecyclerViewは表示が変更される(アイテムの更新、スクロール)時、アイテムのViewをリサイクル(再生利用)します。
これにより余分なViewの作成が行われなくなり、メモリーの節約とパフォーマンスの向上が望めます。
リサイクルはCachedViewsとRecyclerPoolという2つのキャッシュで行われます。
このキャッシュを使ったリサイクルの動作を調べたので紹介します。
目次
アイテムの新規作成とリサイクルの概要
RecyclerViewはアイテムのView(子View)を並べて表示するコンテナタイプのViewです。
表示されているアイテムのViewは、View毎に個別のViewHolder(アイテム内の全View情報をもつクラス)が関連付けられています。
「アイテムのViewをリサイクル」と書きましたが、実際にプログラム内部でリサイクルされるのはViewHolderです。
アイテムが表示されるまでの手順
図はViewHolderを主眼に、アイテムが表示されるまでの手順を示したものです。
アイテムが表示されるまでの手順には4つのケースがあります。
(A)RecyclerViewの起動でアイテムを初めて表示する時に新規作成
(B)RecyclerViewの操作で(スクロール)アイテムを初めて表示する時に新規作成
(C)非表示になったアイテムを再表示する時にCachedViewsからリサイクル
(D)非表示になったアイテムを再表示する時にRecyclerPoolからリサイクル
新規作成(ケースA、B)
キャッシュにViewHolderが存在しない場合です。
必ずAdapter#onCreateViewHolder( )と#onBindViewHolder( )が実行されます。
ただし、(B)は途切れ目のないスクロールを実現するために、前もって作成したViewHolderをCachedViewsへ保持(プリフェッチ)します。そして、アイテムが表示されるタイミングでCachedViewsから取り出し、表示します。
リサイクル(ケースC、D)
キャッシュにViewHolderが存在する場合です。
キャッシュはCachedViewsとRecyclerPoolの2つがあります。
どにちらも非表示になったViewHolderを保持します。違いはViewHolderを参照する鍵が異なることです。
CachedViewはアイテムのポジションを鍵にしています。よって、CachedViewからリサイクルする場合はリサイクル先が同一のポジションでなければなりません。
RecyclerPoolはアイテムのViewTypeを鍵にしています。よって、RecyclerPoolからリサイクルする場合はリサイクル先が同一のViewTypeでなければなりません。また、必ずAdapter#onBindViewHolder( )の実行が必要になります。
アイテムが表示される様子
RecyclerViewでアイテムがスクリーン上に配置され操作(スクロール)される時、ViewHolderの作成・表示・非表示・リサイクルが常に繰り返されています。
このアイテムのライフサイクルと呼ぶべきものが先に述べたケースA・B・C・Dの手順です。
表示されている個々のアイテムがケースA・B・C・Dのどれかに該当し、時々刻々と状態が変化していきます。
アイテムが表示される様子を、アイテムの状態をもとに説明します。
アイテムの状態を得る方法
アイテムが表示される様子を説明する前に、アイテムの状態を得る方法を示します。
実際に動かしてながら確認すれば理解しやすいでしょう!
コールバック
アイテムの状態が変化する毎にコールバックが返るようになっています。状態を知るのに役立ちます。
class ArrayAdapter(var items: Array<String>) : RecyclerView.Adapter<ArrayAdapter.ArrayViewHolder>() { ... override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) : ArrayViewHolder { Log.i("Adapter", "Create ViewHolder!! viewType = ${viewType}") // ViewHolderを新規作成 } override fun onBindViewHolder(holder: ArrayViewHolder, position: Int) { Log.i("Adapter", " Bind ViewHolder!! position = ${position}") // 要素とデータを紐づける } override fun onViewRecycled(holder: ArrayViewHolder) { super.onViewRecycled(holder) val _mesg = holder.mesg.text val _pos = holder.adapterPosition val _type = holder.itemViewType Log.i("Adapter", "View Recycled item = ${_mesg} [pos=${_pos},type=${_type}]") // RecyclerPoolへ保持された } override fun onViewAttachedToWindow(holder: ArrayViewHolder) { super.onViewAttachedToWindow(holder) val _mesg = holder.mesg.text val _pos = holder.adapterPosition val _type = holder.itemViewType Log.i("Adapter", " View Attached item = ${_mesg} [pos=${_pos},type=${_type}]") // アイテムが表示された } override fun onViewDetachedFromWindow(holder: ArrayViewHolder) { super.onViewDetachedFromWindow(holder) val _mesg = holder.mesg.text val _pos = holder.adapterPosition val _type = holder.itemViewType Log.i("Adapter", " View Detached item = ${_mesg} [pos=${_pos},type=${_type}]") // アイテムが非表示になった(CachedViewへ保持された) } }
キャッシュの所在
リサイクル処理はRecyclerView.Recyclerというインナークラスが行っています。
キャッシュ(CachedViews, RecyclerPool)がフィールド定義されているので、適切なタイミングでブレークを張り、デバッガーでフィールド値を確認できます。
ただし、キャッシュに保持されたViewHolderは即座に再生利用されてしまうので、保持されている時間は極短時間です。確認は難しいかも知れません。
public class RecyclerView extends ViewGroup implements ScrollingView, NestedScrollingChild2, NestedScrollingChild3 { ... public final class Recycler { final ArrayList<ViewHolder> mAttachedScrap = new ArrayList<>(); ArrayList<ViewHolder> mChangedScrap = null; final ArrayList<ViewHolder> mCachedViews = new ArrayList<ViewHolder>(); private final List<ViewHolder> mUnmodifiableAttachedScrap = Collections.unmodifiableList(mAttachedScrap); private int mRequestedCacheMax = DEFAULT_CACHE_SIZE; int mViewCacheMax = DEFAULT_CACHE_SIZE; RecycledViewPool mRecyclerPool; private ViewCacheExtension mViewCacheExtension; static final int DEFAULT_CACHE_SIZE = 2; ... } ... public static class RecycledViewPool { private static final int DEFAULT_MAX_SCRAP = 5; ... static class ScrapData { final ArrayList<ViewHolder> mScrapHeap = new ArrayList<>(); int mMaxScrap = DEFAULT_MAX_SCRAP; long mCreateRunningAverageNs = 0; long mBindRunningAverageNs = 0; } SparseArray<ScrapData> mScrap = new SparseArray<>(); ... } ... }
アイテムの状態変化
アイテムが表示される様子を(1)初回表示、(2)スクロール(下方へ)、(3)スクロール(上方へ)の3つに分けて説明します。
アイテムの初回表示
RecyclerViewが起動されて、初めてアイテムが表示される時の様子です。
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 0
... I/Adapter: View Attached item = Item 0 [pos=0,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 1
... I/Adapter: View Attached item = Item 1 [pos=1,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 2
... I/Adapter: View Attached item = Item 2 [pos=2,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 3
... I/Adapter: View Attached item = Item 3 [pos=3,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 4
... I/Adapter: View Attached item = Item 4 [pos=4,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 5
... I/Adapter: View Attached item = Item 5 [pos=5,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 6
... I/Adapter: View Attached item = Item 6 [pos=6,type=0]
アイテムのスクロール(下方へ)
スクロールし、下方のアイテムを表示させる時の様子です。スクロールにより時々刻々(01~15)と変化するアイテムの状態です。
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 7
... I/Adapter: View Attached item = Item 7 [pos=7,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 8
... I/Adapter: View Detached item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item 8 [pos=8,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 9
... I/Adapter: View Detached item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item 9 [pos=9,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 10
... I/Adapter: View Detached item = Item 2 [pos=2,type=0]
... I/Adapter: View Recycled item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item A [pos=10,type=0]
... I/Adapter: Bind ViewHolder!! position = 11
... I/Adapter: View Detached item = Item 3 [pos=3,type=0]
... I/Adapter: View Recycled item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item B [pos=11,type=0]
... I/Adapter: Bind ViewHolder!! position = 12
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 7
... I/Adapter: View Attached item = Item 7 [pos=7,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 8
... I/Adapter: View Detached item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item 8 [pos=8,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 9
... I/Adapter: View Detached item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item 9 [pos=9,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 10
... I/Adapter: View Detached item = Item 2 [pos=2,type=0]
... I/Adapter: View Recycled item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item A [pos=10,type=0]
... I/Adapter: Bind ViewHolder!! position = 11
... I/Adapter: View Detached item = Item 3 [pos=3,type=0]
... I/Adapter: View Recycled item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item B [pos=11,type=0]
... I/Adapter: Bind ViewHolder!! position = 12
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 7
... I/Adapter: View Attached item = Item 7 [pos=7,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 8
... I/Adapter: View Detached item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item 8 [pos=8,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 9
... I/Adapter: View Detached item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item 9 [pos=9,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 10
... I/Adapter: View Detached item = Item 2 [pos=2,type=0]
... I/Adapter: View Recycled item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item A [pos=10,type=0]
... I/Adapter: Bind ViewHolder!! position = 11
... I/Adapter: View Detached item = Item 3 [pos=3,type=0]
... I/Adapter: View Recycled item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item B [pos=11,type=0]
... I/Adapter: Bind ViewHolder!! position = 12
.... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 7
... I/Adapter: View Attached item = Item 7 [pos=7,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 8
... I/Adapter: View Detached item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item 8 [pos=8,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 9
... I/Adapter: View Detached item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item 9 [pos=9,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 10
... I/Adapter: View Detached item = Item 2 [pos=2,type=0]
... I/Adapter: View Recycled item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item A [pos=10,type=0]
... I/Adapter: Bind ViewHolder!! position = 11
... I/Adapter: View Detached item = Item 3 [pos=3,type=0]
... I/Adapter: View Recycled item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item B [pos=11,type=0]
... I/Adapter: Bind ViewHolder!! position = 12
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 7
... I/Adapter: View Attached item = Item 7 [pos=7,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 8
... I/Adapter: View Detached item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item 8 [pos=8,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 9
... I/Adapter: View Detached item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item 9 [pos=9,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 10
... I/Adapter: View Detached item = Item 2 [pos=2,type=0]
... I/Adapter: View Recycled item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item A [pos=10,type=0]
... I/Adapter: Bind ViewHolder!! position = 11
... I/Adapter: View Detached item = Item 3 [pos=3,type=0]
... I/Adapter: View Recycled item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item B [pos=11,type=0]
... I/Adapter: Bind ViewHolder!! position = 12
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 7
... I/Adapter: View Attached item = Item 7 [pos=7,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 8
... I/Adapter: View Detached item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item 8 [pos=8,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 9
... I/Adapter: View Detached item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item 9 [pos=9,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 10
... I/Adapter: View Detached item = Item 2 [pos=2,type=0]
... I/Adapter: View Recycled item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item A [pos=10,type=0]
... I/Adapter: Bind ViewHolder!! position = 11
... I/Adapter: View Detached item = Item 3 [pos=3,type=0]
... I/Adapter: View Recycled item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item B [pos=11,type=0]
... I/Adapter: Bind ViewHolder!! position = 12
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 7
... I/Adapter: View Attached item = Item 7 [pos=7,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 8
... I/Adapter: View Detached item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item 8 [pos=8,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 9
... I/Adapter: View Detached item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item 9 [pos=9,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 10
... I/Adapter: View Detached item = Item 2 [pos=2,type=0]
... I/Adapter: View Recycled item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item A [pos=10,type=0]
... I/Adapter: Bind ViewHolder!! position = 11
... I/Adapter: View Detached item = Item 3 [pos=3,type=0]
... I/Adapter: View Recycled item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item B [pos=11,type=0]
... I/Adapter: Bind ViewHolder!! position = 12
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 7
... I/Adapter: View Attached item = Item 7 [pos=7,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 8
... I/Adapter: View Detached item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item 8 [pos=8,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 9
... I/Adapter: View Detached item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item 9 [pos=9,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 10
... I/Adapter: View Detached item = Item 2 [pos=2,type=0]
... I/Adapter: View Recycled item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item A [pos=10,type=0]
... I/Adapter: Bind ViewHolder!! position = 11
... I/Adapter: View Detached item = Item 3 [pos=3,type=0]
... I/Adapter: View Recycled item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item B [pos=11,type=0]
... I/Adapter: Bind ViewHolder!! position = 12
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 7
... I/Adapter: View Attached item = Item 7 [pos=7,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 8
... I/Adapter: View Detached item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item 8 [pos=8,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 9
... I/Adapter: View Detached item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item 9 [pos=9,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 10
... I/Adapter: View Detached item = Item 2 [pos=2,type=0]
... I/Adapter: View Recycled item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item A [pos=10,type=0]
... I/Adapter: Bind ViewHolder!! position = 11
... I/Adapter: View Detached item = Item 3 [pos=3,type=0]
... I/Adapter: View Recycled item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item B [pos=11,type=0]
... I/Adapter: Bind ViewHolder!! position = 12
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 7
... I/Adapter: View Attached item = Item 7 [pos=7,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 8
... I/Adapter: View Detached item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item 8 [pos=8,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 9
... I/Adapter: View Detached item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item 9 [pos=9,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 10
... I/Adapter: View Detached item = Item 2 [pos=2,type=0]
... I/Adapter: View Recycled item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item A [pos=10,type=0]
... I/Adapter: Bind ViewHolder!! position = 11
... I/Adapter: View Detached item = Item 3 [pos=3,type=0]
... I/Adapter: View Recycled item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item B [pos=11,type=0]
... I/Adapter: Bind ViewHolder!! position = 12
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 7
... I/Adapter: View Attached item = Item 7 [pos=7,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 8
... I/Adapter: View Detached item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item 8 [pos=8,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 9
... I/Adapter: View Detached item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item 9 [pos=9,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 10
... I/Adapter: View Detached item = Item 2 [pos=2,type=0]
... I/Adapter: View Recycled item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item A [pos=10,type=0]
... I/Adapter: Bind ViewHolder!! position = 11
... I/Adapter: View Detached item = Item 3 [pos=3,type=0]
... I/Adapter: View Recycled item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item B [pos=11,type=0]
... I/Adapter: Bind ViewHolder!! position = 12
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 7
... I/Adapter: View Attached item = Item 7 [pos=7,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 8
... I/Adapter: View Detached item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item 8 [pos=8,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 9
... I/Adapter: View Detached item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item 9 [pos=9,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 10
... I/Adapter: View Detached item = Item 2 [pos=2,type=0]
... I/Adapter: View Recycled item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item A [pos=10,type=0]
... I/Adapter: Bind ViewHolder!! position = 11
... I/Adapter: View Detached item = Item 3 [pos=3,type=0]
... I/Adapter: View Recycled item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item B [pos=11,type=0]
... I/Adapter: Bind ViewHolder!! position = 12
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 7
... I/Adapter: View Attached item = Item 7 [pos=7,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 8
... I/Adapter: View Detached item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item 8 [pos=8,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 9
... I/Adapter: View Detached item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item 9 [pos=9,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 10
... I/Adapter: View Detached item = Item 2 [pos=2,type=0]
... I/Adapter: View Recycled item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item A [pos=10,type=0]
... I/Adapter: Bind ViewHolder!! position = 11
... I/Adapter: View Detached item = Item 3 [pos=3,type=0]
... I/Adapter: View Recycled item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item B [pos=11,type=0]
... I/Adapter: Bind ViewHolder!! position = 12
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 7
... I/Adapter: View Attached item = Item 7 [pos=7,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 8
... I/Adapter: View Detached item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item 8 [pos=8,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 9
... I/Adapter: View Detached item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item 9 [pos=9,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 10
... I/Adapter: View Detached item = Item 2 [pos=2,type=0]
... I/Adapter: View Recycled item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item A [pos=10,type=0]
... I/Adapter: Bind ViewHolder!! position = 11
... I/Adapter: View Detached item = Item 3 [pos=3,type=0]
... I/Adapter: View Recycled item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item B [pos=11,type=0]
... I/Adapter: Bind ViewHolder!! position = 12
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 7
... I/Adapter: View Attached item = Item 7 [pos=7,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 8
... I/Adapter: View Detached item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item 8 [pos=8,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 9
... I/Adapter: View Detached item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item 9 [pos=9,type=0]
... I/Adapter: Create ViewHolder!! viewType = 0
... I/Adapter: Bind ViewHolder!! position = 10
... I/Adapter: View Detached item = Item 2 [pos=2,type=0]
... I/Adapter: View Recycled item = Item 0 [pos=0,type=0]
... I/Adapter: View Attached item = Item A [pos=10,type=0]
... I/Adapter: Bind ViewHolder!! position = 11
... I/Adapter: View Detached item = Item 3 [pos=3,type=0]
... I/Adapter: View Recycled item = Item 1 [pos=1,type=0]
... I/Adapter: View Attached item = Item B [pos=11,type=0]
... I/Adapter: Bind ViewHolder!! position = 12
アイテムのスクロール(上方へ)
スクロールし、上方のアイテムを表示させる時の様子です。スクロールにより時々刻々(16~27 ※15からの継続)と変化するアイテムの状態です。
... I/Adapter: View Detached item = Item B [pos=11,type=0]
... I/Adapter: View Recycled item = Item 2 [pos=2,type=0]
... I/Adapter: View Attached item = Item 3 [pos=3,type=0]
... I/Adapter: Bind ViewHolder!! position = 2
... I/Adapter: View Detached item = Item A [pos=10,type=0]
... I/Adapter: View Recycled item = Item C [pos=12,type=0]
... I/Adapter: View Attached item = Item 2 [pos=2,type=0]
... I/Adapter: Bind ViewHolder!! position = 1
... I/Adapter: View Detached item = Item 9 [pos=9,type=0]
... I/Adapter: View Recycled item = Item B [pos=11,type=0]
... I/Adapter: View Attached item = Item 1 [pos=1,type=0]
... I/Adapter: Bind ViewHolder!! position = 0
... I/Adapter: View Detached item = Item 8 [pos=8,type=0]
... I/Adapter: View Recycled item = Item A [pos=10,type=0]
... I/Adapter: View Attached item = Item 0 [pos=0,type=0]
... I/Adapter: View Detached item = Item 7 [pos=7,type=0]
... I/Adapter: View Detached item = Item B [pos=11,type=0]
... I/Adapter: View Recycled item = Item 2 [pos=2,type=0]
... I/Adapter: View Attached item = Item 3 [pos=3,type=0]
... I/Adapter: Bind ViewHolder!! position = 2
... I/Adapter: View Detached item = Item A [pos=10,type=0]
... I/Adapter: View Recycled item = Item C [pos=12,type=0]
... I/Adapter: View Attached item = Item 2 [pos=2,type=0]
... I/Adapter: Bind ViewHolder!! position = 1
... I/Adapter: View Detached item = Item 9 [pos=9,type=0]
... I/Adapter: View Recycled item = Item B [pos=11,type=0]
... I/Adapter: View Attached item = Item 1 [pos=1,type=0]
... I/Adapter: Bind ViewHolder!! position = 0
... I/Adapter: View Detached item = Item 8 [pos=8,type=0]
... I/Adapter: View Recycled item = Item A [pos=10,type=0]
... I/Adapter: View Attached item = Item 0 [pos=0,type=0]
... I/Adapter: View Detached item = Item 7 [pos=7,type=0]
... I/Adapter: View Detached item = Item B [pos=11,type=0]
... I/Adapter: View Recycled item = Item 2 [pos=2,type=0]
... I/Adapter: View Attached item = Item 3 [pos=3,type=0]
... I/Adapter: Bind ViewHolder!! position = 2
... I/Adapter: View Detached item = Item A [pos=10,type=0]
... I/Adapter: View Recycled item = Item C [pos=12,type=0]
... I/Adapter: View Attached item = Item 2 [pos=2,type=0]
... I/Adapter: Bind ViewHolder!! position = 1
... I/Adapter: View Detached item = Item 9 [pos=9,type=0]
... I/Adapter: View Recycled item = Item B [pos=11,type=0]
... I/Adapter: View Attached item = Item 1 [pos=1,type=0]
... I/Adapter: Bind ViewHolder!! position = 0
... I/Adapter: View Detached item = Item 8 [pos=8,type=0]
... I/Adapter: View Recycled item = Item A [pos=10,type=0]
... I/Adapter: View Attached item = Item 0 [pos=0,type=0]
... I/Adapter: View Detached item = Item 7 [pos=7,type=0]
... I/Adapter: View Detached item = Item B [pos=11,type=0]
... I/Adapter: View Recycled item = Item 2 [pos=2,type=0]
... I/Adapter: View Attached item = Item 3 [pos=3,type=0]
... I/Adapter: Bind ViewHolder!! position = 2
... I/Adapter: View Detached item = Item A [pos=10,type=0]
... I/Adapter: View Recycled item = Item C [pos=12,type=0]
... I/Adapter: View Attached item = Item 2 [pos=2,type=0]
... I/Adapter: Bind ViewHolder!! position = 1
... I/Adapter: View Detached item = Item 9 [pos=9,type=0]
... I/Adapter: View Recycled item = Item B [pos=11,type=0]
... I/Adapter: View Attached item = Item 1 [pos=1,type=0]
... I/Adapter: Bind ViewHolder!! position = 0
... I/Adapter: View Detached item = Item 8 [pos=8,type=0]
... I/Adapter: View Recycled item = Item A [pos=10,type=0]
... I/Adapter: View Attached item = Item 0 [pos=0,type=0]
... I/Adapter: View Detached item = Item 7 [pos=7,type=0]
... I/Adapter: View Detached item = Item B [pos=11,type=0]
... I/Adapter: View Recycled item = Item 2 [pos=2,type=0]
... I/Adapter: View Attached item = Item 3 [pos=3,type=0]
... I/Adapter: Bind ViewHolder!! position = 2
... I/Adapter: View Detached item = Item A [pos=10,type=0]
... I/Adapter: View Recycled item = Item C [pos=12,type=0]
... I/Adapter: View Attached item = Item 2 [pos=2,type=0]
... I/Adapter: Bind ViewHolder!! position = 1
... I/Adapter: View Detached item = Item 9 [pos=9,type=0]
... I/Adapter: View Recycled item = Item B [pos=11,type=0]
... I/Adapter: View Attached item = Item 1 [pos=1,type=0]
... I/Adapter: Bind ViewHolder!! position = 0
... I/Adapter: View Detached item = Item 8 [pos=8,type=0]
... I/Adapter: View Recycled item = Item A [pos=10,type=0]
... I/Adapter: View Attached item = Item 0 [pos=0,type=0]
... I/Adapter: View Detached item = Item 7 [pos=7,type=0]
... I/Adapter: View Detached item = Item B [pos=11,type=0]
... I/Adapter: View Recycled item = Item 2 [pos=2,type=0]
... I/Adapter: View Attached item = Item 3 [pos=3,type=0]
... I/Adapter: Bind ViewHolder!! position = 2
... I/Adapter: View Detached item = Item A [pos=10,type=0]
... I/Adapter: View Recycled item = Item C [pos=12,type=0]
... I/Adapter: View Attached item = Item 2 [pos=2,type=0]
... I/Adapter: Bind ViewHolder!! position = 1
... I/Adapter: View Detached item = Item 9 [pos=9,type=0]
... I/Adapter: View Recycled item = Item B [pos=11,type=0]
... I/Adapter: View Attached item = Item 1 [pos=1,type=0]
... I/Adapter: Bind ViewHolder!! position = 0
... I/Adapter: View Detached item = Item 8 [pos=8,type=0]
... I/Adapter: View Recycled item = Item A [pos=10,type=0]
... I/Adapter: View Attached item = Item 0 [pos=0,type=0]
... I/Adapter: View Detached item = Item 7 [pos=7,type=0]
... I/Adapter: View Detached item = Item B [pos=11,type=0]
... I/Adapter: View Recycled item = Item 2 [pos=2,type=0]
... I/Adapter: View Attached item = Item 3 [pos=3,type=0]
... I/Adapter: Bind ViewHolder!! position = 2
... I/Adapter: View Detached item = Item A [pos=10,type=0]
... I/Adapter: View Recycled item = Item C [pos=12,type=0]
... I/Adapter: View Attached item = Item 2 [pos=2,type=0]
... I/Adapter: Bind ViewHolder!! position = 1
... I/Adapter: View Detached item = Item 9 [pos=9,type=0]
... I/Adapter: View Recycled item = Item B [pos=11,type=0]
... I/Adapter: View Attached item = Item 1 [pos=1,type=0]
... I/Adapter: Bind ViewHolder!! position = 0
... I/Adapter: View Detached item = Item 8 [pos=8,type=0]
... I/Adapter: View Recycled item = Item A [pos=10,type=0]
... I/Adapter: View Attached item = Item 0 [pos=0,type=0]
... I/Adapter: View Detached item = Item 7 [pos=7,type=0]
... I/Adapter: View Detached item = Item B [pos=11,type=0]
... I/Adapter: View Recycled item = Item 2 [pos=2,type=0]
... I/Adapter: View Attached item = Item 3 [pos=3,type=0]
... I/Adapter: Bind ViewHolder!! position = 2
... I/Adapter: View Detached item = Item A [pos=10,type=0]
... I/Adapter: View Recycled item = Item C [pos=12,type=0]
... I/Adapter: View Attached item = Item 2 [pos=2,type=0]
... I/Adapter: Bind ViewHolder!! position = 1
... I/Adapter: View Detached item = Item 9 [pos=9,type=0]
... I/Adapter: View Recycled item = Item B [pos=11,type=0]
... I/Adapter: View Attached item = Item 1 [pos=1,type=0]
... I/Adapter: Bind ViewHolder!! position = 0
... I/Adapter: View Detached item = Item 8 [pos=8,type=0]
... I/Adapter: View Recycled item = Item A [pos=10,type=0]
... I/Adapter: View Attached item = Item 0 [pos=0,type=0]
... I/Adapter: View Detached item = Item 7 [pos=7,type=0]
... I/Adapter: View Detached item = Item B [pos=11,type=0]
... I/Adapter: View Recycled item = Item 2 [pos=2,type=0]
... I/Adapter: View Attached item = Item 3 [pos=3,type=0]
... I/Adapter: Bind ViewHolder!! position = 2
... I/Adapter: View Detached item = Item A [pos=10,type=0]
... I/Adapter: View Recycled item = Item C [pos=12,type=0]
... I/Adapter: View Attached item = Item 2 [pos=2,type=0]
... I/Adapter: Bind ViewHolder!! position = 1
... I/Adapter: View Detached item = Item 9 [pos=9,type=0]
... I/Adapter: View Recycled item = Item B [pos=11,type=0]
... I/Adapter: View Attached item = Item 1 [pos=1,type=0]
... I/Adapter: Bind ViewHolder!! position = 0
... I/Adapter: View Detached item = Item 8 [pos=8,type=0]
... I/Adapter: View Recycled item = Item A [pos=10,type=0]
... I/Adapter: View Attached item = Item 0 [pos=0,type=0]
... I/Adapter: View Detached item = Item 7 [pos=7,type=0]
... I/Adapter: View Detached item = Item B [pos=11,type=0]
... I/Adapter: View Recycled item = Item 2 [pos=2,type=0]
... I/Adapter: View Attached item = Item 3 [pos=3,type=0]
... I/Adapter: Bind ViewHolder!! position = 2
... I/Adapter: View Detached item = Item A [pos=10,type=0]
... I/Adapter: View Recycled item = Item C [pos=12,type=0]
... I/Adapter: View Attached item = Item 2 [pos=2,type=0]
... I/Adapter: Bind ViewHolder!! position = 1
... I/Adapter: View Detached item = Item 9 [pos=9,type=0]
... I/Adapter: View Recycled item = Item B [pos=11,type=0]
... I/Adapter: View Attached item = Item 1 [pos=1,type=0]
... I/Adapter: Bind ViewHolder!! position = 0
... I/Adapter: View Detached item = Item 8 [pos=8,type=0]
... I/Adapter: View Recycled item = Item A [pos=10,type=0]
... I/Adapter: View Attached item = Item 0 [pos=0,type=0]
... I/Adapter: View Detached item = Item 7 [pos=7,type=0]
... I/Adapter: View Detached item = Item B [pos=11,type=0]
... I/Adapter: View Recycled item = Item 2 [pos=2,type=0]
... I/Adapter: View Attached item = Item 3 [pos=3,type=0]
... I/Adapter: Bind ViewHolder!! position = 2
... I/Adapter: View Detached item = Item A [pos=10,type=0]
... I/Adapter: View Recycled item = Item C [pos=12,type=0]
... I/Adapter: View Attached item = Item 2 [pos=2,type=0]
... I/Adapter: Bind ViewHolder!! position = 1
... I/Adapter: View Detached item = Item 9 [pos=9,type=0]
... I/Adapter: View Recycled item = Item B [pos=11,type=0]
... I/Adapter: View Attached item = Item 1 [pos=1,type=0]
... I/Adapter: Bind ViewHolder!! position = 0
... I/Adapter: View Detached item = Item 8 [pos=8,type=0]
... I/Adapter: View Recycled item = Item A [pos=10,type=0]
... I/Adapter: View Attached item = Item 0 [pos=0,type=0]
... I/Adapter: View Detached item = Item 7 [pos=7,type=0]
... I/Adapter: View Detached item = Item B [pos=11,type=0]
... I/Adapter: View Recycled item = Item 2 [pos=2,type=0]
... I/Adapter: View Attached item = Item 3 [pos=3,type=0]
... I/Adapter: Bind ViewHolder!! position = 2
... I/Adapter: View Detached item = Item A [pos=10,type=0]
... I/Adapter: View Recycled item = Item C [pos=12,type=0]
... I/Adapter: View Attached item = Item 2 [pos=2,type=0]
... I/Adapter: Bind ViewHolder!! position = 1
... I/Adapter: View Detached item = Item 9 [pos=9,type=0]
... I/Adapter: View Recycled item = Item B [pos=11,type=0]
... I/Adapter: View Attached item = Item 1 [pos=1,type=0]
... I/Adapter: Bind ViewHolder!! position = 0
... I/Adapter: View Detached item = Item 8 [pos=8,type=0]
... I/Adapter: View Recycled item = Item A [pos=10,type=0]
... I/Adapter: View Attached item = Item 0 [pos=0,type=0]
... I/Adapter: View Detached item = Item 7 [pos=7,type=0]
関連記事: