which line(s) of code in the lay out manager invoke (call) method onBindViewHolde (MyViewHolder holder, int position)r?

huangapple go评论79阅读模式
英文:

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) 的注释如下:
// 替换视图的内容(由布局管理器调用)

我的问题是:布局管理器中的哪行代码会调用这个方法?

which line(s) of code in the lay out manager invoke (call) method onBindViewHolde (MyViewHolder holder, int position)r?

英文:

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?

which line(s) of code in the lay out manager invoke (call) method onBindViewHolde (MyViewHolder holder, int position)r?

答案1

得分: 0

在布局阶段调用 onLayoutChildren (RecyclerView.Recycler recycler, RecyclerView.State state) 方法。

提供的 Recycler 用于调用 getViewForPosition (int position) 方法,它在内部管理缓存的视图池并触发适配器的 onCreateViewHolder(如果没有可重用的视图)和 onBindViewHolder,以返回准备添加到视图层次结构的 View

还有预取机制 - collectAdjacentPrefetchPositionscollectInitialPrefetchPositions,用于在当前进行的滚动的预期中创建和绑定视图持有者。

英文:

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.

huangapple
  • 本文由 发表于 2020年10月10日 07:43:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/64288579.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定