在SplashScreen之后我的应用程序中,我正在调用Tabactivity。

在选项卡活动中,我从第一个选项卡切换到另一个名为Float的活动,该活动与TabActivity不相关。通过此活动,当条件变为True时,我想在TabBar中显示第三个选项卡。如何从选项卡活动中打开第三个选项卡。

以下是我的Tabactivity类的代码

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);
    }
}


使用标志或其他任何简单方法对上述事物进行处理,请建议我的朋友,我对android来说是新手

最佳答案

您可以使用标签索引显示第三个标签

tabHost.setCurrentTab(2);

10-08 08:14
查看更多