I'm working on an application and let's say I have 5 different layouts plus a main layout which has links to each layout. In the main layout when the user click to the first button it is suppose to go the related layout by sliding. And It's same for other views.
When the user goes to one of these layouts, the next layout also has a couple of links to other layouts as like a chain. And this chain is moving from layout to the other one by sliding.
I have tried to do this with view flipper but since I have so many different layouts and they have background images and some contents in it, I get out of memory error.
So I'm trying to find a solution in this manner. Any idea how to accomplish this ?
I would recommend you to use Jake Whartons ViewPageIndicator:
Create a Fragment
for every of your Layouts and set the layout to your Fragment with the onCreateView()
methode inside your fragment:
@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:
public Fragment getItem(int position) {
switch(position)
{
case 0:
TestFragment fragment = new TestFragment();
return fragment;
case 1:
TestFragment2 fragment2 = new TestFragment2();
return fragment2;
}
DefaultFragment fragment3 = new DefaultFragment();
return fragment3;
}
Now you should be able to swipe to your Layouts(Fragments) easily