I am using the FragmentPagerAdapter
in my application. In the Adapter I have the following code:
@Override
public Fragment getItem(final int position) {
switch(position){
case 0:
return OffersBasicInfoFragment.newInstance();
case 1:
return OffersSelectedCategoriesFragment.newInstance();
case 2:
return OffersManageArtworkFragment.newInstance();
case 3:
return OffersLegalDisclaimerFragment.newInstance();
case 4:
return OffersSelectStoresFragment.newInstance();
case 5:
return OffersPreviewSaveOfferFragment.newInstance();
default:
return null;
}
}
Now in my onViewCreated
function I have various network calls. Now all of these seven pages get called at the same time. How do I structure my code such that only when the current page is active are the calls made. Meaning when I swipe from Tab1 to Tab2 should the calls in the Tab2 fragment be called.
How can I do this ?