0

I have A ViewPager which have three fragments attached to it. Each fragment has a form which user need to fill out. On last page(Fragment) there is an update button which send the data to server. So I need to collect the data from First and second fragment and get it back in third fragment so that I can send the data to server.

To do that I have just defined Interfaces in first and second fragment which send the data to parent FragmentActivity of-course I have implemented these Interfaces in FragmentActivity. These method save the data in FragmentActivity so that I can get this data in third fragment.

For this I need a callback on swipe so when user swipe from form-1 and form-2 I can send the data to parent FargmentActivity.

Now I don't know when to call these method so that the form-1 and form-2 data in first and second fragment get saved in parent `FragmentActivity'. I have tried all callback method in Fragment but no method get called when user swipe. Any Help would be Appreciated.

Sunny
  • 14,522
  • 15
  • 84
  • 129
  • Hello, Can you help me in this post http://stackoverflow.com/questions/26787650/get-value-of-different-field-in-fragment-from-the-parent-activity – Chlebta Nov 06 '14 at 20:10

1 Answers1

1

You can use a ViewPager.OnPageChangeListener - setOnPageChangeListener(ViewPager.OnPageChangeListener listener)

This will "Set a listener that will be invoked whenever the page changes or is incrementally scrolled"

You would use this in your activity to then request the current data from the current Fragment.

Since this fires on incremental scrolling, you could override FinishUpdate in your PagerAdapter, which seems to be fired when the current view has finished changing.

serenskye
  • 3,467
  • 5
  • 35
  • 51