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 8510375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:41:12+00:00 2026-06-11T03:41:12+00:00

Since TabActivity is deprecated I need to find a way to do it with

  • 0

Since TabActivity is deprecated I need to find a way to do it with Fragments. I have worked with Fragments before I know how it works but I need a guide to create my tab host with FragmentActivities. I have found a couple of examples on the internet, and they are all about putting fragments into a container for the tabs.

What I want is to put FragmentActivities for each tab. Because in my application I will be using 4 tabs and each of the tabs have really complex content in it. As a result, I need to have a FragmentActivity for each tab to manage the Fragments that I will put under each tab within a separated container.

SOLUTION:

After answers and searching on internet I ended up with a Solution. According to the solution I have found, I keep track of Fragments in separated stack for each tab under tab host. Here is my GitHub repository, I created a small sample app for this problem.

  • 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-11T03:41:13+00:00Added an answer on June 11, 2026 at 3:41 am

    Since TabActivity is deprecated I need to find a way to do it with Fragments.

    If you don’t want to use TabActivity – forget about putting FragmentActivities into tab’s content.

    I remind that you can use TabWidget without TabActivity. So you can try this solution:

    1. Create just one FragmentActivity.
    2. Put TabWidget into FragmentActivity‘s layout. Make TabWidget‘s content’s height = 0.
    3. Under TabWidget in XML declare container for you Fragments (FrameLayout for example).
    4. In FragmentActivity just handle which tab is selected (TabHost.OnTabChangeListener) and put needed Fragment into container.
    5. Put programm logics (which was earlier in different activities) into different Fragments.

    Or you can create FragmentActivity with TabWidget, and instead of switching Fragments you can directly put Fragments into each tab’s content.

    For example if you have 3 tabs and 3 fragments try what i do. Call showFragmentX when you need to change one fragment to another.

    public class Test extends FragmentActivity {
    
    private Fragment1 fragment1=new Fragment1();
    private Fragment2 fragment2=new Fragment2();
    private Fragment3 fragment3=new Fragment3();
    
    private void showFragment1(){
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.replace(R.id.fragments_container, fragment1);
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        ft.commit();
    }
    
    private void showFragment2(){
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.replace(R.id.fragments_container, fragment2);
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        ft.commit();
    }
    
    private void showFragment3(){
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.replace(R.id.fragments_container, fragment3);
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        ft.commit();
    }
    
    @Override
    protected void onCreate(Bundle arg0) {
        // TODO Auto-generated method stub
        super.onCreate(arg0);
        setContentView(R.layout.fragmentactivity_layout);
    }
    }
    

    If you do so your fragmentX variables will not be deleted each time you put them in fragment_container. They will live while your FragmentActivity live. Take look at fragments lifecycle.
    Only OnCreateView and onDestroyView methods of fragments will call again and again while you replace one fragment to another.

    Also Fragments has their onSaveInstanceState method where you can save the state of your fragment. For example: user typed his name in fragment1’s editText. If you want to keep this data(name string) while user discover other fragments you should

    1.save name string in fragment1’s onSaveInstanceState method
    2. into fragment1’s onCreateView method check savedInstanceState bundle, if it’s not null – fill edittext with string that you get from bundle.

    public class Fragment1 extends Fragment {
    
    EditText nameEditText;
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,  Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
    
        View fragment1View=inflater.inflate(R.layout.fragment1_layout, container, false);
        nameEditText=(EditText) fragment1View.findViewById(R.id.edittext_name);
    
        //check for saved data. if it is not null - fill your edittext with saved string
        if(savedInstanceState!=null){
            String nameString=(String) savedInstanceState.get("nameString");
            nameEditText.setText(nameString);
        }
        return fragment1View;
    }
    
    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        //save data that user have entered
        outState.putString("nameString", nameEditText.getText().toString());
    }
    

    }

    You can check data before saving. I hope my point is clear now.

    Also if you call setRetainInstance(true) in onCreateView() method of your fragment – system will try to save the state of fragment (with all input data). link to description

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Since now I have only used plugin for editing and the way I use
Since I have no errors I don't know if this is the right place
I develop a tabbed application, and since TabActivity is deprecated, I'm doing it the
since they have same rendering engine, this problem shows in both. it works great
I have an application using TabActivity but it is being rendered incorrectly on ICS.
Since i'm writing a game in RoR, i need to have a game loop
I would like to use tabs in my Android application and since TabActivity is
Since I embeded fetch request in my model.xcdatamodeld, I need an instance of NSManagedObjectModel
Since I've known about Node.js, I've always been a fan of it. But today
Well, im developing and app for api 8 with TabActivity but i found out

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.