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

  • Home
  • SEARCH
  • 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 3693266
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:21:27+00:00 2026-05-19T04:21:27+00:00

I’ve got a project in which I’m trying to do some refactoring of my

  • 0

I’ve got a project in which I’m trying to do some refactoring of my existing TabHosts. I’ve got a bunch of very simple TabHost files that look like the class below. Some actually only have one tab, some 3, etc – so the only real difference in them is the number of tabs and the activity class loaded in each one. I’d like to just create a single TabHost that could get the info out of a passed in Bundle to determine how many tabs and the info needed (spec, indicator, content) to build/add each tab. It seems like the items I can place in the bundle are pretty basic and I’m not familiar with the Parcelable or Serializable features. Any suggestions?

public class   SomeTabHost
       extends ActivityGroup
{   
   @Override
   public void onCreate(Bundle savedInstanceState)
   {
      super.onCreate(savedInstanceState);

      // Inflate ourselves into the layout ViewStub
      ViewStub vs = (ViewStub) findViewById(R.id.theViewStub);
      vs.setLayoutResource(R.layout.my_tabhost); 
      vs.inflate();

      TabHost host = (TabHost) findViewById(android.R.id.tabhost);
      host.setup(getLocalActivityManager());

      host.addTab(host.newTabSpec("Tab1")
                      .setIndicator("Tab1")
                      .setContent(new Intent(this, SomeActivity.class)));

      host.addTab(host.newTabSpec("Tab2")
                      .setIndicator("Tab2")
                      .setContent(new Intent(this, SomeOtherActivity.class)));

      int numChildren = host.getTabWidget().getChildCount();
      for ( int i=0; i  <numChildren; i++ )
      {
         host.getTabWidget().getChildAt(i).getLayoutParams().height = 35;
      }
   }// end onCreate
}// end class
  • 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-05-19T04:21:28+00:00Added an answer on May 19, 2026 at 4:21 am

    Looks like I jumped in asking this question too soon. I ended up solving my problem using a Serializable class implementation. Hopefuly somebody else finds this useful. See the code below:

    First created class to hold the data

    public class TabDetails implements Serializable
    {
       private static final long serialVersionUID = 1L;
    
       public String   tabSpec      = "";
       public String   tabIndicator = "";
       public Class<?> tabContent   = null;
    
       public TabDetails( String   aTabSpec,
                          String   aTabIndicator, 
                          Class<?> aTabContent )
       {
          this.tabSpec      = aTabSpec;
          this.tabIndicator = aTabIndicator;
          this.tabContent   = aTabContent;
       }
    }//end class
    

    Then updated the Generic Tab Host

    public class GenericTabHost extends ActivityGroup
    {   
       public static final String TABS = "TABS";
    
       @Override
       public void onCreate(Bundle savedInstanceState)
       {          
          super.onCreate(savedInstanceState);
    
          // Inflate ourselves into the layout ViewStub
          ViewStub vs = (ViewStub) findViewById(R.id.theViewStub);
          vs.setLayoutResource(R.layout.mc_tabhost);
          vs.inflate();      
    
          TabHost host = (TabHost) findViewById(android.R.id.tabhost);
          host.setup(getLocalActivityManager());
    
          Bundle bundle = this.getIntent().getExtras();
    
          if ( null != bundle )
          {
             ArrayList<TabDetails> tabDetailsList = (ArrayList<TabDetails>) bundle.getSerializable(GenericTabHost.TABS);
    
             for ( TabDetails tabDetails : tabDetailsList )
             {
                host.addTab(host.newTabSpec  ( tabDetails.tabSpec     )
                                .setIndicator( tabDetails.tabIndicator)
                                .setContent  ( new Intent( getApplicationContext(),
                                                           tabDetails.tabContent   ));
                }
    
                int numChildren = host.getTabWidget().getChildCount();
                for ( int i=0; i  <numChildren; i++ )
                {
                   host.getTabWidget().getChildAt(i).getLayoutParams().height = 35;
                } 
             }
          }
          else
          {
             Log.e("GenericTabHost", "#### This class must be passed in data to build itself ####");
          }
    
       }// end onCreate
    
    }// end class
    

    The user of this class can use it like:

    ArrayList<TabDetails> tabDetailsArray = new ArrayList<TabDetails>(2);
    tabDetailsArray.add(new TabDetails("Tab_1",  
                                       "Tab 1",  
                                        SomeActivity.class));
    tabDetailsArray.add(new TabDetails("Tab_2",  
                                       "Tab 2",  
                                       AnotherActivity.class));
    
    Intent intent = new Intent(getApplicationContext(), GenericTabHost.class); 
    intent.putExtra(GenericTabHost.TABS, tabDetailsArray);
    startActivity(intent);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.