BaseAdapter和ArrayAdapter有什么区别? [英] What's the difference between BaseAdapter and ArrayAdapter?
问题描述
我想知道使用BaseAdapter
和ArrayAdapter
的区别.
I want to know the difference between using BaseAdapter
and ArrayAdapter
.
我一直在通过ArrayAdapters
实现我想要的.
I have been achieving what I want through ArrayAdapters
.
它会影响ListView
在实现它的适配器接口上的性能吗?
Does it affect the performance of the ListView
on the adapter interface in which it is implemented ?
最后一个问题是,我可以使用这些Adapters
中的任何一个来实现ListView
的任何功能,还是在某些情况下只能使用特定的适配器?
And, the last question is, can i achieve anything doing with ListView
using any of these Adapters
, or, there are certain cases where specific adapter only can be used?
推荐答案
以下是区别:
-
BaseAdapter
是一个非常通用的适配器,可让您执行几乎所有您想做的事情.但是,您需要自己编写一些代码才能使其正常工作. -
ArrayAdapter
是一个更完整的实现,非常适合数组或ArrayList
中的数据.同样,如果数据位于Cursor
中,则应使用相关的CursorAdapter
.这两个都扩展了BaseAdapter
.
BaseAdapter
is a very generic adapter that allows you to do pretty much whatever you want. However, you have to do a bit more coding yourself to get it working.ArrayAdapter
is a more complete implementation that works well for data in arrays orArrayList
s. Similarly, there is a relatedCursorAdapter
that you should use if your data is in aCursor
. Both of these extendBaseAdapter
.
如果您的数据属于某种专门的集合,或者您不希望ArrayAdapter
提供的默认行为,则可能需要扩展BaseAdapter
以获得所需的灵活性.
If your data is in a specialized collection of some sort or if you don't want the default behavior that ArrayAdapter
provides, you will likely want to extend BaseAdapter
to get the flexibility you need.
每个组件的性能实际上取决于您如何实现它们或更改它们的行为.在他们的核心上,任何一个都可以同样有效(尤其是考虑到ArrayAdapter
是一个BaseAdapter
).
The performance of each really depends on how you implement them or change their behavior. At their core, either one can be just as effective (especially considering that an ArrayAdapter
is a BaseAdapter
).
您可以使用任何适配器执行几乎任何您想做的事,但是请记住,BaseAdapter
是抽象的,因此您不能直接使用它.
You can do pretty much whatever you want with any adapter, but keep in mind that BaseAdapter
is abstract, so you can't use it directly.
这篇关于BaseAdapter和ArrayAdapter有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!