Get list of items in custom adapter
android
Solution
I am not sure this works so would have rather added it as a suggesting in the form of a comment, but it was too lengthy. You could try something like this
List<T> items = new ArrayList<T>();
for(int i = 0; i < adapter.getCount(); i++){
items.add(adapter.getItem(i));
}
Or you should be able to create a simple getter in your adapter for the list it contains
public T getList(){
return mList;
}
- note that T is a generic representation of the item type you are working with
It seems that if you have your adapter and it's methods setup correctly that should work. Again, not sure if it actually does and there is likely a better method. Just thought I would toss in my 2 cents really quick. If it doesn't work let me know and I will delete the answer to avoid confusion for other users.
Problem
So, I have a custom adapter extending ArrayAdapter, and I wanna get the entire list from within the adapter, is it possible to do that? I know that in the ArrayAdapter constructor, you pass in the list of objects and it stores it as mObjects, but that list is private. I thought of just creating my own list in my custom adapter in the constructor but it cannot get changed by the adapter.add(...) method. Is there a way to access the up-to-date list? Or is there any way i can update the list of objects i initialised in my custom adapter's constructor? Help!