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

The Archive Base Latest Questions

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

In Androd_Tab_view.java file, I have the following code : tabs = (TabHost)findViewById(R.id.TabHost1); tabs.setup(); TabHost.TabSpec

  • 0

In Androd_Tab_view.java file, I have the following code :

tabs = (TabHost)findViewById(R.id.TabHost1);
tabs.setup();

TabHost.TabSpec first_tab = tabs.newTabSpec("tag1");
first_tab.setContent(new Intent(this,FirstTab.class));
first_tab.setIndicator("Book");
tabs.addTab(first_tab);
//SecondTab.class
TabHost.TabSpec second_tab = tabs.newTabSpec("tag2");
second_tab.setContent(new Intent(this,SecondTab.class));
second_tab.setIndicator("Authors");
tabs.addTab(second_tab);

In FirstTab.java file I have the following code :

public class FirstTab extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

/* First Tab Content */
        TextView textView = new TextView(this); 
        textView.setText("First Tab");
        setContentView(textView);

    }
}

In SecondTab.java file I have the following code :

     public class SecondTab extends Activity {
/** Called when the activity is first created. */
@Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);  /* Second Tab Content */

        TextView textView = new TextView(this);
        textView.setText("Second Tab"); 
        setContentView(textView);

    }
}

But when I try to run this code I get an exception . What can be possible solution 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-12T09:11:55+00:00Added an answer on June 12, 2026 at 9:11 am

    You create Tab like this

       void tabCreation() {
    
        tabHost.setup();
    
        TabSpec spec1 = tabHost.newTabSpec("Accounts");
        spec1.setIndicator(createTabView(tabHost.getContext(), "Accounts", R.drawable.tab_home));
        Intent inte = new Intent(TabsActivity.this,  Activityone.class);
        inte.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        spec1.setContent(inte);
        // spec1.setContent(R.id.tab1);
    
        TabSpec spec2 = tabHost.newTabSpec("Contacts");
        spec2.setIndicator(createTabView(tabHost.getContext(), "Contacts", R.drawable.tab_account));
        Intent _int = new Intent(TabsActivity.this,  Activitytwo.class);
        _int.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        spec2.setContent(_int);
        // /spec2.setContent(R.id.tab2);
    
        TabSpec spec3 = tabHost.newTabSpec("Chats");         
    
        tabHost.addTab(spec1);
        tabHost.addTab(spec2);       
    
        tabHost.setCurrentTab(0);
    }
    
    private static View createTabView(final Context context, final String text, final int id) {
    
        View view = LayoutInflater.from(context).inflate(R.layout.tab_indicator, null);
        TextView tv = (TextView) view.findViewById(R.id.title);
        tv.setText(text);
        ImageView icon = (ImageView) view.findViewById(R.id.icon);
        icon.setImageResource(id);
        return view;
    }
     }
    

    and your Activities are

     public class FirstTab extends Activity {
      /** Called when the activity is first created. */
        @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_accounts); 
    
    
        /* First Tab Content */
           TextView textView = new TextView(this); 
           textView.setText("First Tab");
          setContentView(textView);
    

    and

      public class secondTab extends Activity {
      /** Called when the activity is first created. */
        @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.contacts_accounts); 
    
    
        /* First Tab Content */
           TextView textView = new TextView(this); 
           textView.setText("First Tab");
          setContentView(textView);
    
        }
    }
    

    and tis http://www.androidhive.info/2011/08/android-tab-layout-tutorial/

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

Sidebar

Related Questions

I am using following code to add tabs on a tabHost but crashes on
I have problem with initializing TabHost. I need to have in View several Tabs
I have an android activity in which I'm using tabs. public class UnitActivity extends
Im trying to set my tabs as a scrollbar. I have 6 tabs but
[Solution at the bottom] I need a tab to have the following behaveyour but
I want to display compose email in Tab Activity. It is my code. TabHost
I have an Android app where i'm using tabs (with ActionBarSherlock). So my main
Let's get straight to code. Activity Code, onCreate method setContentView(R.layout.main); View main_view = findViewById(R.id.main_view);
In the following app the tabs will show correctly but I can't determine why
I'm trying to use a webview inside a tabhost that has 4 tabs -

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.