GetView 对比。自定义 CursorAdapter 中的 BindView?
所以,我正在观看此视频 http://www.youtube.com/watch?v=N6YdwzAvwOA 和 Romain Guy 展示了如何使用 getView()
方法编写更高效的 UI 适配器代码。这也适用于 CursorAdapters 吗?我目前正在使用 bindView()
和 newView()
作为我的自定义光标适配器。我应该使用 getView 吗?
So, I'm watching this video http://www.youtube.com/watch?v=N6YdwzAvwOA and Romain Guy is showing how to make more efficient UI adapter code using the getView()
method. Does this apply to CursorAdapters as well? I'm currently using bindView()
and newView()
for my custom cursor adapters. Should I be using getView instead?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
CursorAdapter
有一个getView()
的实现,它委托给newView()
和bindView()
,在这样的情况下方式 as 强制执行行回收模式。因此,如果您要重写newView()
和bindView()
,则无需使用CursorAdapter
进行任何特殊操作即可进行行回收。CursorAdapter
has an implementation ofgetView()
that delegates tonewView()
andbindView()
, in such a way as enforces the row recycling pattern. Hence, you do not need to do anything special with aCursorAdapter
for row recycling if you are overridingnewView()
andbindView()
.这个CursorAdapter源码,显然cursorAdapter的工作量比较多。
This CursorAdapter source code, clearly cursorAdapter work more.
CursorAdapter
实现与子类化常规适配器(如BaseAdapter
)不同,您不需要重写getView()
、getCount ()
、getItemId()
因为可以从游标本身检索该信息。给定一个 Cursor,您只需要重写两个方法即可创建一个 CursorAdapter 子类:
bindView()
:给定一个视图,更新它以显示提供的游标中的数据。newView()
:调用它来构造一个进入列表的新视图。CursorAdapter 将负责回收视图(与常规 Adapter 上的 getView() 方法不同)。它不会在每次需要新行时调用
newView()
。如果它已经有一个View
(不是null
),它会直接调用bindView()
,这样,创建的视图就会被重用。通过将每个视图的创建和填充分为这两个方法,CursorAdapter
实现了视图重用,而在常规适配器中,这两件事都是在getView()
方法中完成的。The
CursorAdapter
implementation is different from sub-classing regular adapters likeBaseAdapter
, you don't need to overridegetView()
,getCount()
,getItemId()
because that information can be retrieved from the cursor itself.Given a
Cursor
, you only need to override two methods to create aCursorAdapter
subclass:bindView()
: Given a view, update it to display the data in the provided cursor.newView()
: This gets called to consctruct a new view that goes into the the list.The
CursorAdapter
will take care of recycling views (unlike thegetView()
method on regularAdapter
). It doesn't call thenewView()
each time it needs a new row. If it already has aView
(notnull
), it will directly call thebindView()
, this way, the created view is reused. By splitting the creation and population of each view into these two methods, theCursorAdapter
achieves view reuse where as, in regular adapters, both these things are done ingetView()
method.