Android Listview Arrayadapter
Solution 1:
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.
Solution 2:
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.
Solution 3:
Both cases are possible, here explain how the second case helps optimize your listviews: http://developer.android.com/training/improving-layouts/smooth-scrolling.html
Post a Comment for "Android Listview Arrayadapter"