0

I'd like to come up with a solution to the following problem:

I have a FragmentViewPager holding 4 fragments. The first one holds a Spinner with an OnItemSelected listener which gets triggered at startup (due to how spinners work). Then, if I swipe all the way to the last fragment, the first Fragment gets destroyed. After that, if I swipe this time to the first fragment, it is created again and the Spinner's OnItemSelectedListener gets triggered again, which I don't want.

How should I prevent the Spinner from triggering its listener on fragment changes from the FragmentPagerAdapter?

Gonzalo
  • 3,674
  • 2
  • 26
  • 28
  • 1
    If you're not messing with `setOffScreenPageLimit()` you could let the `Fragment` with the `Spinner` observe the current selected page in the `ViewPager`. If, when the `Fragment` with the `Spinner` gets recreated, the `ViewPager` is at page `2` then it means we're getting recreated ahead time by the `ViewPager` and simply ignore the event. – user Sep 21 '13 at 05:05
  • Well, I wasn't aware of `setOffScreenPageLimit()`. That saved the day :D Thank you! – Gonzalo Sep 30 '13 at 04:35

0 Answers0