Siva Kannabiran
Siva Kannabiran

Reputation: 27

Calling different tabs from normal activity in android

in my app after the SplashScreen i am calling a Tabactivity.

In tha tab activity, from the first tab i am switched over to a another activity called as Float, which is not related to the TabActivity. From this activity when a condition becomes True i want to show the third tab in the TabBar. How to open the third tab from the tab activity.

Following is the code of my Tabactivity class

public class MainTabBar extends TabActivity 
{
    TabHost tabHost;
    Intent intent;

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.maintab);


          addTab1(Display.class);
          addTab2(History.class); 
          addTab3(Capture    .class);
          addTab4(AboutUs.class);
    }

    private void addTab1( Class<?> c)
    {
        TabHost tabHost = getTabHost();
        Intent intent = new Intent(this, c);
        TabHost.TabSpec spec = tabHost.newTabSpec("Tab1");  

        View tabIndicator = LayoutInflater.from(this).inflate(R.layout.hometab, getTabWidget(), false);
        spec.setIndicator(tabIndicator);
        spec.setContent(intent);
        tabHost.addTab(spec);
    }

    private void addTab2( Class<?> c)
    {
        TabHost tabHost = getTabHost();
        Intent intent = new Intent(this, c);
        TabHost.TabSpec spec = tabHost.newTabSpec("Tab2");  

        View tabIndicator = LayoutInflater.from(this).inflate(R.layout.macstab, getTabWidget(), false);
        spec.setIndicator(tabIndicator);
        spec.setContent(intent);
        tabHost.addTab(spec);
    }

    private void addTab3( Class<?> c)
    {
        TabHost tabHost = getTabHost();
        Intent intent = new Intent(this, c);
        TabHost.TabSpec spec = tabHost.newTabSpec("Tab3");  

        View tabIndicator = LayoutInflater.from(this).inflate(R.layout.abouttab, getTabWidget(), false);        
        spec.setIndicator(tabIndicator);
        spec.setContent(intent);
        tabHost.addTab(spec);
    }

    private void addTab4( Class<?> c)
    {
        TabHost tabHost = getTabHost();
        Intent intent = new Intent(this, c);
        TabHost.TabSpec spec = tabHost.newTabSpec("Tab4");  

        View tabIndicator = LayoutInflater.from(this).inflate(R.layout.contacttab, getTabWidget(), false);      
        spec.setIndicator(tabIndicator);
        spec.setContent(intent);
        tabHost.addTab(spec);
    }
}

Is it to the above thing using a flag or any other easy way, pls suggest me friends, i am very new to android

Upvotes: 1

Views: 709

Answers (1)

Munish Kapoor
Munish Kapoor

Reputation: 3339

You can use the tab index to show the third tab

tabHost.setCurrentTab(2);

Upvotes: 1

Related Questions