2011-10-21 52 views

回答

2

有可能把一個TabActivity一個Tab內。

假設你有MainTabActivity兩個Tabs。首先Tab可以再抱FirstSubTabActivity和第二Tab可容納SecondSubTabActivity

下面是一個例子:

主要活動:

public class MainTabActivity extends TabActivity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     TabHost tabHost = getTabHost(); 
     TabHost.TabSpec spec; 
     Intent intent; 

     intent = new Intent().setClass(this, FirstSubTabActivity.class); 
     spec = tabHost.newTabSpec("FirstTab").setIndicator("One").setContent(intent); 
     tabHost.addTab(spec); 

     intent = new Intent().setClass(this, SecondSubTabActivity.class); 
     spec = tabHost.newTabSpec("SecondTab").setIndicator("Two").setContent(intent); 
     tabHost.addTab(spec); 
    } 
} 

第一子活動:

public class FirstSubTabActivity extends TabActivity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     TabHost tabHost = getTabHost(); 
     TabHost.TabSpec spec; 
     Intent intent; 

     intent = new Intent().setClass(this, SomeActivity.class); 
     spec = tabHost.newTabSpec("SubTab").setIndicator("One").setContent(intent); 
     tabHost.addTab(spec); 

     intent = new Intent().setClass(this, SomeOtherActivity.class); 
     spec = tabHost.newTabSpec("AnotherSubTab").setIndicator("Two").setContent(intent); 
     tabHost.addTab(spec); 
    } 
} 

第二子活動:

public class SecondSubTabActivity extends TabActivity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     TabHost tabHost = getTabHost(); 
     TabHost.TabSpec spec; 
     Intent intent; 

     intent = new Intent().setClass(this, SomeThirdActivity.class); 
     spec = tabHost.newTabSpec("ThirdSubTab").setIndicator("One").setContent(intent); 
     tabHost.addTab(spec); 

     intent = new Intent().setClass(this, SomeFourthActivity.class); 
     spec = tabHost.newTabSpec("FourthSubTab").setIndicator("Two").setContent(intent); 
     tabHost.addTab(spec); 
    } 
} 
+0

非常感謝,這說明子標籤手動添加,你有什麼想法如何使編程,而無需使用2個活動? – Waypoint

相關問題