简体   繁体   English

如何在 android 中为不同的布局使用不同的 tabhosts

[英]how to use different tabhosts for different layouts in android

I know how to write tab host,but here the scenario is little bit different我知道如何编写选项卡主机,但这里的情况有点不同
I have a screen,in that 2 tabs are there 1.ABC 2.XYZ when ever we click on the XYZ tab next page onwords we need to display 4 other tabs P,Q,R,S how to set tabhosts to meet the above criteria please specify any suggestions我有一个屏幕,其中有 2 个选项卡 1.ABC 2.XYZ 当我们单击下一页的 XYZ 选项卡时,我们需要显示 4 个其他选项卡 P、Q、R、S 如何设置 tabhosts 以满足上述要求标准 请具体说明任何建议

You just need to create two classes that extends TabActivity您只需要创建两个扩展 TabActivity 的类

First that contains首先包含

1.ABC
2.XYZ

Second contains第二个包含

1.P
2.Q
3.R
4.S

Now you have to call startActivity with the Intent of second TabActivity inside onTabChanged() so when Tab XYZ is selected open the second TabActivity. Now you have to call startActivity with the Intent of second TabActivity inside onTabChanged() so when Tab XYZ is selected open the second TabActivity.

Add that method into your TabActivity:将该方法添加到您的 TabActivity 中:

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

        spec.setIndicator(name);
        spec.setContent(intent);
        tabHost.addTab(spec);
    }

    public void addMyFourNewTabs()
    {
        addTab("P", PActivity.class);
        addTab("Q", QActivity.class);
        addTab("R", RActivity.class);
        addTab("S", SActivity.class);
    }

In your Activity where you want to create the new Tabs:在您要创建新选项卡的活动中:

((TabActivity) getParent()).getTabHost().addMyFourNewTabs();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM