How to switch the adapter for the gallery

Is it possible for me to dynamically switch the adapter to the gallery?

In onCreate()my activity, I did this:

myGallery.setAdapter(adapter1);

And then in my code I did

myGallery.setAdapter(anotherAdapter1);

I tried, but in the emulator myGallery never updates when I add "setAdapter" again. How can I make myGallery release all the elements when it used adapter1, and then forces it to refill the elements for anotherAdapter1?

Thanks.

+3
source share
1 answer

you need to call notifyDataSetChanged () on the adapter

a.notifyDataSetChanged();

which will update your changes to the gallery view.

+1
source

Source: https://habr.com/ru/post/1710960/


All Articles