1 package org.shuxiang.tabhostsample; 2 3 import android.os.Bundle; 4 import android.app.ActivityGroup; 5 import android.content.Intent; 6 import android.widget.TabHost; 7 8 public class MainActivity extends ActivityGroup 9 { 10 private String tabHost1 = "A"; 11 private String tabHost2 = "B"; 12 private String tabHost3 = "C"; 13 private TabHost tabHost; 14 15 @Override 16 public void onCreate(Bundle savedInstanceState) { 17 super.onCreate(savedInstanceState); 18 setContentView(R.layout.tabhost); 19 20 tabHost = (TabHost) findViewById(android.R.id.tabhost); 21 22 tabHost.setup(getLocalActivityManager()); 23 24 tabHost.setCurrentTab(0); 25 tabHost.addTab(tabHost.newTabSpec(tabHost1) 26 .setIndicator(tabHost1). 27 setContent(new Intent(MainActivity.this, Tab1.class))); 28 tabHost.addTab(tabHost.newTabSpec(tabHost2) 29 .setIndicator(tabHost2) 30 .setContent(new Intent(MainActivity.this, Tab2.class))); 31 tabHost.addTab(tabHost.newTabSpec(tabHost3) 32 .setIndicator(tabHost3) 33 .setContent(new Intent(MainActivity.this, Tab3.class))); 34 35 } 36 37 38 }