Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between BaseAdapter and ArrayAdapter?

I want to know the difference between using BaseAdapter and ArrayAdapter.

I have been achieving what I want through ArrayAdapters.

Does it affect the performance of the ListView on the adapter interface in which it is implemented ?

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?

like image 903
Chintan Soni Avatar asked May 28 '13 15:05

Chintan Soni


People also ask

What is the difference between ArrayAdapter and BaseAdapter?

Here is the difference: 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 ArrayList s.

What is ArrayAdapter used for?

You can use this adapter to provide views for an AdapterView , Returns a view for each object in a collection of data objects you provide, and can be used with list-based user interface widgets such as ListView or Spinner .

What is difference between adapter and AdapterView?

An Adapter is responsible for creating and binding data to views. An Adapter isn't an actual view, but instead produces them. An AdapterView is a ViewGroup that gets its child views from an Adapter . E.g. a ListView has a child view for each row in its list.


2 Answers

Here is the difference:

  • 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.

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.

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).

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.

like image 103
Bryan Herbst Avatar answered Oct 04 '22 07:10

Bryan Herbst


BaseAdapter is abstract while ArrayAdapter extends BaseAdapter (it is a concrete implementation of a BaseAdapter). If you extends for ArrayAdapter you are inheriting all the ArrayAdapter's features and, override its implementation you can modify the ArrayAdapter behavior. If you extends BaseAdapter you must implements all the Abstract methods, that ArrayAdapter already implements.

Also, does it affects the performance of the ListView

no it does not.

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 ?

If the implementation in the SDK fulfill your needs why you need to override it and re-invent the wheel?

The main difference between them is that BaseAdapter can not be instantiate while ArrayAdapter can

like image 21
Blackbelt Avatar answered Oct 04 '22 06:10

Blackbelt