Here is my code
public static class TestPagerAdapter extends FragmentPagerAdapter {
Context mContext;
public TestPagerAdapter(FragmentManager fm, Context context) {
super(fm);
this.mContext = context;
}
@Override
public int getCount() {
//it is 3
return NUM_ITEMS;
}
@Override
public Fragment getItem(int position) {
Fragment fm = null;
switch (position) {
case 0 :
case 1 :
case 2 :
fm = TestListFragment.getInstance(mContext, position);
//fm.setRetainInstance(true);
}
return fm;
}
}
Static method in TestFragment to instantiate
public static TestListFragment getInstance(Context context, int position) {
fragmentInstance = new TestListFragment();
fragmentInstance.context = context;
Bundle args = new Bundle();
args.putInt("num", position);
fragmentInstance.setArguments(args);
return fragmentInstance;
}
Problem:
1- There are total three instances of TestListFragment for each position in TestPagerAdapter. everything works fine but when swipe back to 0th or 2nd it calls getitem and done the whole stuff like onCreateView them onActivityCreated is this intended behavior?
2- As FragmentPAgerAdapter does all that checking by itself then why it is still re-instantiating the fragment. Do I need to do this as mentioned here
3- I am using ListFragments all 3 listfragment uses different adapter where is the appropriate location to setAdapter? I am doing it in onActivityCreated.
4- why fm.setRetainInstance(true) is not working? (I am expecting that making it true will not re-instantiate the fragment)
Hope I made my problem clear..