Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7980227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:00:16+00:00 2026-06-04T10:00:16+00:00

I have an application which has a TabHost set up with 5 tabs. These

  • 0

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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T10:00:19+00:00Added an answer on June 4, 2026 at 10:00 am

    I eventually figured it out, I changed the XML file to this

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
                 <FrameLayout
                        android:id="@+id/TheFragment"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" >
                    </FrameLayout>
    
    </RelativeLayout>
    

    And then in the FragmentActivity I created this method

    protected void changeFragment(Fragment removeFrag, Fragment f)
        {
            FragmentTransaction ft = fm.beginTransaction();
            ft.setCustomAnimations(R.anim.view_transition_in_left,
                    R.anim.view_transition_out_left);
            ft.replace(R.id.TheFragment, f);
            ft.remove(removeFrag);
            ft.addToBackStack(null);
            ft.commit();
        }
    

    Then in each fragment when user clicked next button would do something like this

    Fragment f = ((Tab1) getActivity()).fragTwo;
                Fragment rf = ((Tab1) getActivity()).fragOne;
    
    
                ((Tab1) getActivity()).changeFragment(rf, f);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a Flex application which has several 'pages' worth of content. Each time
Hi I have an application which has a main project set to ver 3.5
I'm a bit puzzeled, I have an application which has 5 tabs in tabHost.
I have made an application which has tabs like in HelloTabActivity, there is also
I have an application which has two Tabs. Both of these are ListFragments. The
I have an application which has several functions in it. Each function can be
I have an Android application which has the main UI thread, and several other
I have an Android application which has four tabs (I use a main TabActivity
I have an application which has the following characteristics There are Clubs Each Club
I have an application which has 11 different activities. One of these activities is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.