To extend CommonsWare an excellent answer and populate it with code so you can imagine:
If you have a Jake Wharton demo project for ViewPageIndicator, you should have TestFragmentAdapter and TestFragment . The TestFragmentAdapter class extends the FragmentPagerAdapter class, and the TestFragment class must extend the Fragment . Currently, the "Actions" paging wand is not possible, but you can scroll through fragments.
Create a Fragment and set it to your layout using the onCreateView() method inside your fragment:
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.layout, container, false); }
Your FragmentPagerAdapter can now have a method called getItem() . Switch Position and set it to fragment:
@Override public Fragment getItem(int position) { switch(position){ case 0: TestFragment fragment = new TestFragment(); return fragment; case 1: TestFragment2 fragment2 = new TestFragment2(); return fragment2; } return defaultFragment fragment3 = new defaultFragment(); return fragment3; }
Now it should work the way you want it.
Ahmad source share