Skip to content

@luksprog /FragmentPagerAdapter.java
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
public class FragmentPagerActivity extends FragmentActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.blank_main);
//Setting the adapter
ViewPager mViewPager = (ViewPager) super.findViewById(R.id.mysixpanelpager);
mViewPager.setAdapter(initialisePaging());
mViewPager.setOffscreenPageLimit(2);
mViewPager.setCurrentItem(0);
}
private PagerAdapter initialisePaging() {
// Fragments to initialise
MainActivity mMainActivityFragment = new MainActivity();
Bundle args = new Bundle();
args.putInt("pagerId", R.id.mysixpanelpager);
mMainActivityFragment.setArguments(args);
OneMain mOneMainFragment = new OneMain();
TwoMain mTwoMainFragment = new TwoMain();
ThreeMain mThreeMainFragment = new ThreeMain();
FourMain mFourMainFragment = new FourMain();
FiveMain mFiveMainFragment = new FiveMain();
// Process of initialisation
PagerAdapter myFPadapter = new PagerAdapter(getSupportFragmentManager());
myFPadapter.addFragment(mMainActivityFragment);
myFPadapter.addFragment(mOneMainFragment);
myFPadapter.addFragment(mTwoMainFragment);
myFPadapter.addFragment(mThreeMainFragment);
myFPadapter.addFragment(mFourMainFragment);
myFPadapter.addFragment(mFiveMainFragment);
return myFPadapter;
}
private static class PagerAdapter extends FragmentPagerAdapter {
private final ArrayList<Fragment> mFragments = new ArrayList<Fragment>();
public PagerAdapter(FragmentManager fm) {
super(fm);
}
public void addFragment(Fragment fragment) {
mFragments.add(fragment);
notifyDataSetChanged();
}
@Override
public int getCount() {
return mFragments.size();
}
@Override
public Fragment getItem(int position) {
return mFragments.get(position);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.