Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BaseAdapter or ArrayAdaptor - Android

Tags:

android

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?

like image 638
Casebash Avatar asked Jul 28 '10 03:07

Casebash


People also ask

Why ArrayAdapter is used in Android?

resource: It is used to set the layout file(. xml files) for the list items.

What are the different types of adapters in Android?

Android provides several subclasses of Adapter that are useful for retrieving different kinds of data and building views for an AdapterView ( i.e. ListView or GridView). The common adapters are ArrayAdapter,Base Adapter, CursorAdapter, SimpleCursorAdapter,SpinnerAdapter and WrapperListAdapter.

What is the base adapter in Android?

BaseAdapter, as it's name implies, is the base class for so many concrete adapter implementations on Android. It is abstract and therefore, cannot be directly instantiated. If your data source is an ArrayList or array, we can also use the ArrayAdapter construct as an alternative.

What is adapter list out adapter which you know?

In Android, Adapter is a bridge between UI component and data source that helps us to fill data in UI component. It holds the data and send the data to an Adapter view then view can takes the data from the adapter view and shows the data on different views like as ListView, GridView, Spinner etc.


1 Answers

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.

like image 193
CommonsWare Avatar answered Nov 07 '22 11:11

CommonsWare