问题描述
我在我的项目覆盖的方法自定义的 CursorAdaptor
bindView(查看视图,上下文的背景下,光标光标)
和 NewView的(查看视图,上下文的背景下,光标光标)
。我想知道是什么的CursorAdapter
用于,什么是压倒一切的和用途之间的差异 bindView()
和 NewView的()
。
I have a custom CursorAdaptor
in my project with overridden methods bindView(View view, Context context, Cursor cursor)
and newView(View view, Context context, Cursor cursor)
.I want to know for what CursorAdapter
are used for and what is the difference between and uses of overriding bindView()
and newView()
.
我已经阅读了开发者网站和的的教程,但我仍然不明白。由于我是一个初学者到Android,请帮我理解这个概念。
I have read the Developer Site and this tutorial but still I didn't understood. As I'm a beginner to Android, please help me understand this concept.
推荐答案
为了理解这一点,你必须首先了解如何 BaseAdapter
的作品,因为的CursorAdapter
是一个子类 BaseAdapter
。
In order to understand this, you must first understand how BaseAdapter
works, since CursorAdapter
is a subclass of BaseAdapter
.
Android的维护视图池中的的ListView
它将给你,让你可以重用创建一个新的观点,每次它代替。
Android maintains a pool of views for a ListView
which it will give to you so you can reuse it instead of creating a new view each time.
在 BaseAdapter
,你将有一个名为 getView()
功能,其中的参数之一是命名视图
对象 convertView
。基本上,这个 convertView
将空
如果列表被加载的第一次,也不会是空
一旦你开始滑动列表。因此,在 getView()
方法,你的 BaseAdapter
,你会如果 convertView 是
空
。如果是的话,你将它充气。然后您可以使用该视图,并将其作为正常的元素。这将提高一个列表视图极大的滚动性能。
In BaseAdapter
, you will have a function called getView()
, to which one of the parameters is a View
object named convertView
. Basically, this convertView
will be null
if the list is being loaded for the first time, and it will not be null
once you start sliding the list. Therefore, in the getView()
method of your BaseAdapter
, you will check if convertView
is null
. If yes, you will inflate it. Then you can use the view and set its elements as normal. This will improve the scrolling performance of a listview tremendously.
A 的CursorAdapter
使得它易于使用,当ListView的数据源是一个数据库。在游标适配器,但是,Android的需要检查 convertView
是否为空
或不关心。在 NewView的()
方法,你只需膨胀的观点,并将其返回。在 bindView()
方法,设置视图的元素。
A CursorAdapter
makes it easy to use when the data source of a listview is a database. In a cursor adapter, however, Android takes care of checking whether the convertView
is null
or not. In the newView()
method, you simply inflate the view and return it. In the bindView()
method, you set the elements of your view.
作为一个例子,设想可以显示高达在屏幕上11的列表项目设备上的列表视图。在这种情况下, NewView的()
将被称为高达11倍。然而, bindView()
每当您滚动列表视图会被调用很多次。您在NewView的方法创建的11次为您滚动列表会被一次又一次的重复使用。
As an example, imagine a listview on a device which can show upto 11 list items on the screen. In this case, newView()
will be called upto 11 times. However, bindView()
will be called many times whenever you scroll the list view. The 11 views you created in your newView method will be reused again and again as you scroll the list.
这篇关于什么bindView()和NewView的()做的CursorAdapter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!