【问题标题】:How to add a tab to TabView如何将选项卡添加到 TabView
【发布时间】:2014-10-20 15:09:50
【问题描述】:

我正在尝试为我的 android 应用程序构建一个 TabView。这是我的java代码

    public class AllMain extends TabActivity{

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.all_main);

            // create the TabHost that will contain the Tabs
            TabHost tabHost = getTabHost();
            Resources res = getResources();

            TabSpec tab1 = tabHost.newTabSpec("First Tab").setIndicator("Tab1").setContent(new Intent().setClass(this, TabAll_all.class));
            TabSpec tab2 = tabHost.newTabSpec("Second Tab").setIndicator("Tab2").setContent(new Intent().setClass(this, TabAll_all.class));
            TabSpec tab3 = tabHost.newTabSpec("Third tab").setIndicator("Tab3").setContent(new Intent().setClass(this, TabAll_all.class));

            tabHost.addTab(tab3);
            tabHost.addTab(tab1);
            tabHost.addTab(tab2);

            tabHost.setCurrentTab(0);
        }

    }

但是当我运行应用程序时,应用程序关闭并显示“不幸停止”消息。

我意识到在下面的行评论不会给我错误

            tabHost.addTab(tab3);
            tabHost.addTab(tab1);
            tabHost.addTab(tab2);

提前致谢。

【问题讨论】:

    标签: android android-tabhost tabview


    【解决方案1】:

    向 Manifest 文件添加一个新活动就可以了

    谢谢

    【讨论】:

      猜你喜欢
      • 2021-09-13
      • 1970-01-01
      • 1970-01-01
      • 2021-06-20
      • 2019-12-12
      • 2018-07-31
      • 1970-01-01
      • 2018-12-10
      • 2013-08-18
      相关资源
      最近更新 更多