Question

Is it possible for me to dynamically switch the adapter of a Gallery?

In the onCreate() of my activity, I did this:

myGallery.setAdapter(adapter1);

And then later on in my code, I did

myGallery.setAdapter(anotherAdapter1);

I tried, that but in the emulator, the myGallery never gets update when I do 'setAdapter' again. How can I force myGallery free up all the items when it was using adapter1 and then makes it repopulate items for anotherAdapter1?

Thank you.

Was it helpful?

Solution

you need to call notifyDataSetChanged() to the adapter

a.notifyDataSetChanged();

that will refresh your changes to the gallery view.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top