I was wondering, is there any guideline, on how we choose between ArrayAdapter
and SimpleAdapter
.
For every list item, they will be presented by several TextViews and Views, which is being layout nicely. I realize I can implement both without any problem, by either using ArrayAdapter
or SimpleAdapter
.
Is there any guideline, on how we choose among them? My guess is
ArrayAdapter
enables us to add in new item dynamically, even after the list is being shown during that time. Note that, ArrayAdapter
is having method add
.SimpleAdapter
is used for case, once the list is being shown, there are no more new item can be added.Is this the guideline we should follow?
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.
resource: It is used to set the layout file(. xml files) for the list items.
In Android development, any time we want to show a vertical list of scrollable items we will use a ListView which has data populated using an Adapter . The simplest adapter to use is called an ArrayAdapter because the adapter converts an ArrayList of objects into View items loaded into the ListView container.
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.
Personally, I don't find SimpleAdapter
terribly useful. Your model data is rarely naturally in "an ArrayList
of Maps
", and it is wasteful to be copying stuff around just to get it in an adapter.
I would either use ArrayAdapter
(if my model data is an array of objects) or BaseAdapter
(if my model data is some other in-memory data structure).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With