在TabHost中每个tab启动不同的activitie

/***
*
* Main class - Container.java
*
public class Container extends TabActivity {
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		TabHost host = getTabHost();
		host.addTab(host.newTabSpec("Activity1").setIndicator("TAB1").setContent(new Intent(this, Tab1Activity.class)));
		host.addTab(host.newTabSpec("Activity2").setIndicator("TAB2").setContent(new Intent(this, Tab2Activity.class)));
	}
}


/***
*
* Tab1Activity.java
*

public class Tab1Activity extends Activity{
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        setContentView(R.layout.tab1);
	}
}

/***
*
* Tab2Activity.java
*

public class Tab2Activity extends Activity{
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        setContentView(R.layout.tab2);
	}
}



/***
*
* res/layout/main.xml
*

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
</LinearLayout>


/***
*
* res/layout/tab1.xml
*

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="tab1"
    />
</LinearLayout>


/****
*
* res/layout/tab2.xml
*

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="tab2"
    />
</LinearLayout>

/***
*
* res/values/strings.xml
*

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, Container!</string>
    <string name="app_name">MultipleActivityTabHost</string>
</resources>




/***
*
* AndroidManifest.xml
*

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.novoda"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="3" />
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Container"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    <activity android:name="Tab1Activity"></activity>
<activity android:name="Tab2Activity"></activity>
</application>
</manifest>

 

你可能感兴趣的:(android,xml)