【问题标题】:Calling different tabs from normal activity in android从android中的正常活动调用不同的选项卡
【发布时间】:2012-03-09 04:11:28
【问题描述】:

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

在这个选项卡活动中,我从第一个选项卡切换到另一个名为 Float 的活动,它与 TabActivity 无关。从这个活动中,当条件变为真时,我想在 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);
    }
}

上面的事情是用flag还是其他简单的方法,请朋友们推荐我,我对android很陌生

【问题讨论】:

    标签: android android-intent tabs tabbar


    【解决方案1】:

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

    tabHost.setCurrentTab(2);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多