I have an application which has a TabHost set up with 5 tabs. These tabs are fragment activities. In each of these fragment activities, there is are several fragments set up.
My Main class sets up the tabHost and fragment activities like so
public class Main extends TabActivity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
Resources res = getResources();
tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this,
Tab1.class);
spec = tabHost
.newTabSpec("home")
.setIndicator("Home",
res.getDrawable(R.drawable.tabhome))
.setContent(intent);
tabHost.addTab(spec);
//and do this for the other 4 tabs
tabHost.setCurrentTab(0);
}
}
Then my fragmentActivities are set up like this
public class Tab1 extends FragmentActivity
{
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
FragmentTransaction fragmentTransaction = getSupportFragmentManager()
.beginTransaction();
// Fragments
Fragment fragOne = new FragmentOne();
Fragment fragTwo = new FragmentTwo();
Fragment fragThree = new FragmentThree();
fragmentTransaction.replace(R.id.fragmentOne, fragOne);
fragmentTransaction.replace(R.id.fragmentTwo, fragTwo);
fragmentTransaction.replace(R.id.fragmentThree, fragThree);
fragmentTransaction.commit();
}
}
Tab1 Fragment Activity has 3 fragments as you can see above. Each Fragment, FragmentOne, FragmentTwo and FragmentThree each contain a next button inside the fragments.
What I would like to know is how do I set it up so they transition between each fragment within the class. E.g.
Frag1 (in Frag1 click next button ), Frag 2 transitions from the right (in Frag2 here click next button) Frag3 transitions in from the right (in Frag3, click next button) Frag1 transitions in from the right.
Any assistance would be much appreciated!!!
Edit: Will also paste how the fragments are set up in the home.xml layout file incase your wondering how I set it up.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/homeMain"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/FragmentOneRL"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/fragmentOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</FrameLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/FragmentTwoRL"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_below="@+id/FragmentOneRL"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/fragmentTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</FrameLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/FragmentThreeRL"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_below="@+id/FragmentTwoRL"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/fragmentThree"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</FrameLayout>
</RelativeLayout>
</RelativeLayout>
I eventually figured it out, I changed the XML file to this
And then in the FragmentActivity I created this method
Then in each fragment when user clicked next button would do something like this