2014-10-20 105 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

添加一個新的活動清單文件的伎倆

感謝

相關問題