Getting all of the items from an ArrayAdapter
The solution that I've gone with in the meantime is just to not use ArrayAdapter
. In cases where you're fighting against this API, it seems like it's better just to use the less fully-featured (and complex) BaseAdapter
. You can read more about the decision to go with BaseAdapter
instead of ArrayAdapter
in this article: Android Adapter Good Practices.
I'm a little late to the game, but I've run up against a similar issue.
One way to deal with #1 would be to maintain the reference to the list within a subclass of ArrayAdapter
, so that your reuse is controlled by the adapter object.
Something like:
public class DomainAdapter extends ArrayAdapter<DomainObject> {
private final List<DomainObject> items;
public DomainAdapter(Context context, List<DomainObject> items) {
super(context, R.layout.mine, items);
this.items = items;
}
public List<DomainObject> getItems() {
return items;
}
}