2014-10-20 157 views
0

我想为我的android应用程序构建一个TabView。这是我的java代码如何将选项卡添加到TabView

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

在此先感谢。

+1

发表您的logcat – mmlooloo 2014-10-20 15:40:42

回答

0

添加一个新的活动清单文件的伎俩

感谢

相关问题