I have set up custom horizontal paging in my app with lets say 5 pages. Each page has its own ListView and ListView Adapter. In my main Activity class, I have an ArrayList of custom objects that I use to hydrate each ListView.
So in my main class, I can call:
lvAdapter.setItems(items);
Works fine.
But when I call:
lvAdapter.clearItems();
I only want it to clear the items in the ListView, but it actually removes all the items from my ArrayList for that object. I suppose the Adapter is only holding a reference?
Adapter clearItems:
public void clearItems()
{
this.items.clear(); //this will remove the object in the ArrayList
this.notifyDataSetChanged();
}
What I am trying to do is setItems on actively visible pages and clearItems for those pages that are not visible. Because I am dealing with out of memory crashes when I load all the pages at once…
You could clear the adapter reference for that
ListViewe.g.listView.setAdapter(null)I would also read up on efficient
Adapterimplementations, there are several things you can do to reduce memory footprint e.g. recycling views properly ingetView(...)