StableArrayAdapter vs ArrayAdapter

I look at this ListView tutorial:

ListView Tutorial

and I was wondering how much better it is to create your own ArrayAdapter, and not just use an ArrayAdapter.

In the tutorial, he defines "StableArrayAdapter", what exactly does this mean? if I use a regular arrayAdapter, could it be dangerous for some reason?

+4
source share
4 answers

The two previous answers are absolutely correct, but for a more direct answer to your question even if someone has the same doubts as you do; the usual ArrayAdapter is not dangerous at all, the only "problem" is that it may not meet your needs, in which case you will need to create your own adapter, as the author of the tutorial, creating what he called StableArrayAdapter at the end of the ListViewExampleActivity class.

Do not lose the name, which I think comes from the fact that the rewritten hasStableIds method always returns true, this does not mean that the usual ArrayAdapter creates problems.

+6
source

ArrayAdapter: This is just a way to provide data in a ListView. It is also a BaseAdapter that is supported by an array of objects.

CustomAdapter: If your ListView is a regular and simple ListView (in which you have one TextView for each item in the list), then using an ArrayAdapter will be apt. But it is recommended that you create your own CustomAdapter that extends the ArrayAdapter, which you can use to provide data in the ListView. This way you can easily expand your ListView to include more than one TextView or even an ImageView (to display images).

CursorAdapter: The cursor adapter is used when you have data in the cursor (usually when you retrieve data from a database. The cursor must contain a column named "_id" or this class will not work.

+5
source

If you use a simple ListView, for example, just a TextView for each element, then just use the standard ArrayAdapter , on the other hand, if you need a custom element in the list, as in combinations of views in each in the ListView, then expand the ArrayAdapter and implement it in accordance with your needs.

+4
source

The StableArrayAdapter is just an extended version of the ArrayAdapter, but in the StableArrayAdapter they redefined the hasStableIds () BaseAdapter method to return true.

You can check this in the following links:

StableArrayAdapter - Override hasStableIds to return true

ArrayAdapter - Does not override hasStableIds, but an extended base adapter

BaseAdapter - Has hasStableIds, but returns false

Now the question is using StableIds

This indicates whether the item identifiers are resistant to changes in the underlying data. If True, then the same identifier always refers to the same object. for more information

+2
source

Source: https://habr.com/ru/post/1493573/


All Articles