Reputation: 11678
i'm using an ArrayAdapter in my ListView.
I can't really understand if when i'm setting and ArrayList to my ArrayAdapter, it recreate all the objects of it, or just reference to it.
for some reason same objects which are supposed to be the same in too list views, doesn't get effected with property changes as if the current object is a clone of the other object..
can anyone please clear that out ?
Upvotes: 0
Views: 1116
Reputation: 1906
Both cases are possible, here explain how the second case helps optimize your listviews: http://developer.android.com/training/improving-layouts/smooth-scrolling.html
Upvotes: 0
Reputation: 68167
When you pass ArrayList
to an ArrayAdapter
, it actually manipulates object using Pass-by Reference.
And when you alter the contents of your ArrayList
and want to reflect those changes in ArrayAdapter
, then you must need to call notifyDataSetChanged()
method of your adapter.
P.S: Practically you should pass a cloned object of your ArrayList to adapter (unless you know what you are doing), since its unnecessary and will take extra resources.
More info.
Upvotes: 1
Reputation: 63293
It depends on how you create the ArrayAdapter
.
If you use a version of the constructor that does not take an array or List
as a parameter, then it will create a new list that each adapter instance maintains. If you create your adapter with one of the following versions:
ArrayAdapter(Context context, int textViewResourceId, List<T> objects)
ArrayAdapter(Context context, int resource, int textViewResourceId, List<T> objects)
Then you can supply the same external list to multiple adapters and change your data set only once, because in this case the adapter just references your list and doesn't copy the data.
Upvotes: 0