BaseAdapter 和 ArrayAdapter 有什么区别? [英] What's the difference between BaseAdapter and ArrayAdapter?

查看:24
本文介绍了BaseAdapter 和 ArrayAdapter 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道使用BaseAdapterArrayAdapter 的区别.

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 or ArrayLists. Similarly, there is a related CursorAdapter that you should use if your data is in a Cursor. Both of these extend BaseAdapter.

如果您的数据位于某种专门的集合中,或者如果您不想要 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 is 一个 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆