Search code examples
android-fragmentsmvvmandroid-viewpagerlisteneronclicklistener

How to pass custom listener from Fragment to VM in MVVM?


My app has a bottom nav with 3 Fragments where first one has a ViewPager with tablayout each having their own Fragments.

What I want to do is change the content of fragments of viewpager fragments depending on the selection of Spinner selected.

How do i implement a listener to listen for change in Spinner to change the data calls to repo in each of the ViewModels.

Any other solutions are also welcome.


Solution

  • This may not be ideal solution, but I was able to work it out using SharedPreference and SharedPreference Listener. I also came across LiveData to observe SharedPreference, but this was easier and much simpler. Also see this answer