Reputation: 3855
I am looking at this ListView
Tutorial:
and I was wondering how much better is to create my own ArrayAdapter
, rather than just using and ArrayAdapter
.
In the Tutorial it defines a "StableArrayAdapter
", what exactly does this means? If I use a regular ArrayAdapter
, could it be dangerous for some reason?
Upvotes: 4
Views: 9713
Reputation: 239
StableArrayAdapter is merely an extended version of ArrayAdapter, but in StableArrayAdapter they have overridden the method hasStableIds() of BaseAdapter to return true.
You can check this in the following links:
StableArrayAdapter - Override hasStableIds to return true
ArrayAdapter - Has not Override hasStableIds but extended BaseAdapter
BaseAdapter - Has hasStableIds but returning false
This Indicates whether the item ids are stable across changes to the underlying data. If True then same id always refers to the same object. for more info
Upvotes: 2
Reputation: 5336
The two previous answers are absolutely right, but just to address more directly your question and in case someone else has the same doubt than you; a regular ArrayAdapter is not dangerous at all, the only "problem" is that it might not fulfill your needs, in which case you will have to create your own adapter, as the author of the tutorial did by creating what he called StableArrayAdapter in the end of the ListViewExampleActivity class.
Don't get lost by the name, which I guess comes from the fact that the overwritten method "hasStableIds" always returns true, it doesn't mean that the regular ArrayAdapter creates problems.
Upvotes: 6
Reputation: 3910
If you are using a simple ListView, like merely a TextView per item, then just use the standard ArrayAdapter
, on the other hand, if you want a custom item in the list, as in a combinations of views within each item in the ListView, then extend the ArrayAdapter
and implement it to your needs.
Upvotes: 4
Reputation: 1111
ArrayAdapter: It is merely a way to provide data to a ListView. It is also a BaseAdapter that is backed by an array of objects.
CustomAdapter: If if your ListView is a normal and simple ListView (wherein you are having one TextView per item in the list), then the use of ArrayAdapter would be apt. But it is recommended you to create your own CustomAdapter which extends an ArrayAdapter that you can use for providing data to your ListView. This way you can easily extend your ListView to include more that one TextView or even ImageView (to show images).
CursorAdapter: Cursor Adapter is used when you have Data in a Cursor (typically when you are retrieving data from a database. The Cursor must include a column named "_id" or this class will not work.
Upvotes: 5