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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:18:05+00:00 2026-06-05T02:18:05+00:00

I use TabHost and i have 2 tabs with 2 activityes i want to

  • 0

I use TabHost and i have 2 tabs with 2 activityes i want to set second tab to be default tab but when tabhost start he load first tab1 and before tab2 an this is wrong because in these 2 activityes i load data from webservice !
My question is how to set current tab second tab without load first tab!

My tabhost code:

public class TabsHandler extends TabActivity    {
private static TabHost tabHost;
Intent intent;
    private void setupTabHost() {
    tabHost = (TabHost) findViewById(android.R.id.tabhost);
    tabHost.setup(this.getLocalActivityManager());
    tabHost.setCurrentTab(1);
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            if(!isOnline())
                Utils.DialogNoInternet(this);
            String authToken = getIntent().getExtras().getString("token");
            Long role = getIntent().getExtras().getLong("role");
            String EventIdNotification =getIntent().getExtras().getString("EventIdNotification");
            setContentView(R.layout.event_list_tabs);    

            setupTabHost();
            Resources res = getResources();
            tabHost.getTabWidget().setClipChildren(false);


            setupTab(new TextView(this), res.getString(R.string.tab1_List),new Intent().setClass(this, EventListActivity.class).putExtra("authToken", authToken).putExtra("role", role).putExtra("EventIdNotification", EventIdNotification));
            setupTab(new TextView(this), res.getString(R.string.tab2_List),new Intent().setClass(this, PastEventListActivity.class).putExtra("authToken", authToken).putExtra("role", role).putExtra("isPast", "true"));
            tabHost.setCurrentTab(1);



    }
    public void switchTab(int tab){
            tabHost.setCurrentTab(tab);
    }
    public boolean isOnline() {
        ConnectivityManager cm =
            (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = cm.getActiveNetworkInfo();
        if (netInfo != null && netInfo.isConnectedOrConnecting()) {
            return true;
        }
        return false;
    }
    private void setupTab(final View view, final String tag,Intent intent) {
            View tabview = createTabView(tabHost.getContext(), tag);
            TabSpec setContent = tabHost.newTabSpec(tag);
            setContent.setIndicator(tabview);
            setContent.setContent(intent);
            tabHost.addTab(setContent);
    }

    private static View createTabView(final Context context, final String text) {

            View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
            TextView tv = (TextView) view.findViewById(R.id.tabsText);
            tv.setText(text);
            return view;
    }
  • 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-05T02:18:06+00:00Added an answer on June 5, 2026 at 2:18 am
    public class TabsHandler extends TabActivity    {
    private static TabHost tabHost;
       Intent intent;
    private void setupTabHost() {
    tabHost = (TabHost) findViewById(android.R.id.tabhost);
    tabHost.setup(this.getLocalActivityManager());
    tabHost.setCurrentTab(2);
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            if(!isOnline())
                Utils.DialogNoInternet(this);
            String authToken = getIntent().getExtras().getString("token");
            Long role = getIntent().getExtras().getLong("role");
            String EventIdNotification =getIntent().getExtras().getString("EventIdNotification");
            setContentView(R.layout.event_list_tabs);    
    
            setupTabHost();
            Resources res = getResources();
            tabHost.getTabWidget().setClipChildren(false);
    
    
            setupTab(new TextView(this), res.getString(R.string.tab1_List),new Intent().setClass(this, EventListActivity.class).putExtra("authToken", authToken).putExtra("role", role).putExtra("EventIdNotification", EventIdNotification));
            setupTab(new TextView(this), res.getString(R.string.tab2_List),new Intent().setClass(this, PastEventListActivity.class).putExtra("authToken", authToken).putExtra("role", role).putExtra("isPast", "true"));
            tabHost.setCurrentTab(2);
    
    
    
    }
    public void switchTab(int tab){
            tabHost.setCurrentTab(tab);
    }
    public boolean isOnline() {
        ConnectivityManager cm =
            (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = cm.getActiveNetworkInfo();
        if (netInfo != null && netInfo.isConnectedOrConnecting()) {
            return true;
        }
        return false;
    }
    private void setupTab(final View view, final String tag,Intent intent) {
            View tabview = createTabView(tabHost.getContext(), tag);
            TabSpec setContent = tabHost.newTabSpec(tag);
            setContent.setIndicator(tabview);
            setContent.setContent(intent);
            tabHost.addTab(setContent);
    }
    
    private static View createTabView(final Context context, final String text) {
    
            View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
            TextView tv = (TextView) view.findViewById(R.id.tabsText);
            tv.setText(text);
            return view;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used to use : tabHost.getTabWidget().getChildAt(0).getLayoutParams().height =50; to set my tab height. But I
I want to use TabHost, but my app has stopped unexpectedly. I don't really
I have a method in Test1Activity that creates tabs inside a TabHost, but if
I have an application with various tabs (on a tabhost). Each tab is an
Hey, I have a TabHost with two tabs, each with an Activity. The first
In my application I have a tabHost with 5 tabs. And I want to
I have a tabhost where I need to use onTabChanged listener, but it does
I want to use more than one CheckBox in each tab, but only one
I have an Android application that is a TabHost with a WebView. I use
I have an app that uses a TabHost. Several of the Tabs share a

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.