0

I have several fragments. I want them to come one after another as ViewPager. If i swipe right then a fragment will be destroyed storing a value "yes" and if i swipe left it will destroy storing a value "no" and next fragment will appear. I tried FragmentStatePagerAdapter but not getting desired result. I have google a lot but unable to do as I want.

Suppose I have 3 fragments 1,2,3. 1 is the first fragment. If I swipe right/left fragment 1 will destroy storing a value and fragment 2 will appear, and so on. When swiping to last fragment, a Dialog box will pop up with completion message.

Marcus
  • 6,697
  • 11
  • 46
  • 89
Patriotic
  • 2,103
  • 4
  • 26
  • 36

1 Answers1

0

Your ViewPager does not destroy your fragment, when you swipe from fragmet 1 to fragment 2. However, if you swipe from fragment 2 to fragment 3, fragment 1 is destroyed. This also applies to when you swipe from fragment 2 to fragment 1. In that case, fragment 3 is destroyed.

If you want to store a value between swipes, you should probably use the onPause callback method of the respective fragment.

Marcus
  • 6,697
  • 11
  • 46
  • 89
  • if i swipe 1 to 2,then 3 ,1 will be destroy but when i swipe back destroyed fragments comes again...Specially i want to destroy a fragment forever after swiping.... @Marcus – Patriotic Mar 19 '15 at 17:35
  • Yes, your `ViewPager` recreates the Fragments if the user decides to "swipe back". If you want to stop your `ViewPager` from swiping in a particular direction, thus stopping it from recreating fragments, you could have a look at [this question](http://stackoverflow.com/questions/12224581/viewpage-stop-swiping-in-a-certain-direction). @user3751576 – Marcus Mar 20 '15 at 14:03