I would recommend you to use Jake Whartons ViewPageIndicator(or just a normal ViewPager):
Create a Fragment
for every of your Layouts and set the layout to your Fragment with the onCreateView()
methode inside your fragment(only if you want to have different layouts. If you have the same Layout but just different data, you can just use one Fragment and pass the data in the getItem() methode)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.layout, container, false);
}
Now create a FragmentPagerAdapter
there sould be a methode called getItem()
. Switch
the Position and set it to your 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 you should be able to swipe to your Layouts(Fragments) easily