英文:
which line(s) of code in the lay out manager invoke (call) method onBindViewHolde (MyViewHolder holder, int position)r?
问题
在这个 Android 开发者文档 https://developer.android.com/guide/topics/ui/layout/recyclerview#java 中,MyAdapter 类中的方法 onBindViewHolder(MyViewHolder holder, int position) 的注释如下:
// 替换视图的内容(由布局管理器调用)
我的问题是:布局管理器中的哪行代码会调用这个方法?
英文:
In this Android developer document https://developer.android.com/guide/topics/ui/layout/recyclerview#java , the annotation of the method onBindViewHolder(MyViewHolder holder, int position) in the MyAdapter class reads:
// Replace the contents of a view (invoked by the layout manager)
My question is: which line(s) of code in the lay out manager invoke (call) this method?
答案1
得分: 0
在布局阶段调用 onLayoutChildren (RecyclerView.Recycler recycler, RecyclerView.State state)
方法。
提供的 Recycler
用于调用 getViewForPosition (int position)
方法,它在内部管理缓存的视图池并触发适配器的 onCreateViewHolder
(如果没有可重用的视图)和 onBindViewHolder
,以返回准备添加到视图层次结构的 View
。
还有预取机制 - collectAdjacentPrefetchPositions
和 collectInitialPrefetchPositions
,用于在当前进行的滚动的预期中创建和绑定视图持有者。
英文:
During layout phase onLayoutChildren (RecyclerView.Recycler recycler, RecyclerView.State state)
is called.
Provided Recycler
is used to call getViewForPosition (int position)
which internally manages cached view pool and triggers adapters onCreateViewHolder
(if there's no view to reuse) and onBindViewHolder
to return View
that's ready to be added to view hierarchy.
There are also prefetching mechanisms - collectAdjacentPrefetchPositions
and collectInitialPrefetchPositions
which are used to create and bind viewholders in anticipation of currently ongoing scroll.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论