I want to have different tabs, where you can swipe through like in the android market. Each tab should use one fragment and use one method for it.
This is my Fragmen
In your FragmentPagerAdapter#getItem method, do not create object of the Fragments. You need to return the Fragment in the following way -
return Fragment.instantiate(context, ConnectionFragment.class.getName());
This means that the method will look like this -
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
Fragment fragment =null;
switch (position) {
case 0:
fragment = Fragment.instantiate(context, ConnectionFragment.class.getName());
break;
case 1:
fragment = Fragment.instantiate(context, DataFragment.class.getName());
break;
case 2:
fragment = Fragment.instantiate(context, GraphFragment.class.getName());
break; }
return fragment;
}
@Override
public int getCount() {
// Show 3 total pages.
return 3;
}
}