本文介绍了BaseAdapter或ArrayAdaptor - 安卓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要使图像的网格,我试图找出是否使用数组适配器或baseadaptor。虽然 GridView的例子,存储在阵列中的数据,它采用了BaseAdapter,而不是一个ArrayAdaptor。我很好奇这是为什么。有一件事我注意到了有关的ArrayAdapter,是它的构造函数需要一个 textViewResourceId 由于一些未知的原因 - 虽然文件说,getView可以用来使其与其他种类的工作,意见也是如此。所以,如果我想要一个图像定格的菜单,哪个类,你会推荐选择?

I am going to make a grid of images and I am trying to figure out whether to use an array adaptor or a baseadaptor. While the GridView example, stores the data in an array, it uses a BaseAdapter rather than a ArrayAdaptor. I am curious why this is. One thing I noticed about an ArrayAdapter, is that its constructor takes a textViewResourceId for some unknown reason - although the documentation say the getView can be used to make it work with other kinds of views as well. So, if I want a fixed grid of images for a menu, which class would you recommend choosing?

推荐答案

您通常选择基于模型的数据是你的适配器类。如果你有一个的ArrayList 的对象,使用 ArrayAdapter 。如果从数据库查询有一个光标,使用的CursorAdapter BaseAdapter 可用于任何东西,但它需要更多的代码,因为它有一个如何遍历数据没有良知。

You typically choose your adapter class based on what the model data is. If you have an ArrayList of objects, use ArrayAdapter. If you have a Cursor from a database query, use a CursorAdapter. BaseAdapter can be used for anything, but it requires more coding, since it has no innate knowledge of how to iterate over the data.

这篇关于BaseAdapter或ArrayAdaptor - 安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 20:37