Home > Back-end >  Close bottomsheet and when open it again the changes will still be there
Close bottomsheet and when open it again the changes will still be there

Time:06-09

I made a bottomsheet with a couple of items, I make some changes into it and apply (it will close the bottomsheet), but when I open it again the bottomsheet resets, how can I keep the values that I chose before? It's a bottomSheetFragment. I want to save selected value from recyclerView and a number, how can I do it?

CodePudding user response:

When you close a bottom sheet fragment it's view gets destroyed. So when you create it again it reinitialize all of it's views hence the data is lost.

So, if you want to keep the data saved you can use a viewModel, and in onStop of bottom sheet fragment you can store all of the required data in view model and again reload it onCreateView of bottom sheet fragment.

  • Related