========================================================== ====================================
1. Add a button to the main activity and use the button to jump to the tab.
Private button tabviewbutton = NULL; Public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); tabviewbutton = (button) findviewbyid (R. id. tabviewbutton); tabviewbutton. setonclicklistener (New tabviewbuttonlistener ();} // use the intent object to switch to class tabviewbuttonlistener implements onclicklistener {public void onclick (view arg0) in the activity of the tab) {// todo auto-generated method stub intent = new intent (); intent. setclass (tabviewtest. this, tabviewdemo. class); tabviewtest. this. startactivity (intent );}}
2. Create a tab layout file, tab_value.xml
<Framelayout xmlns: Android = "http://schemas.android.com/APK/RES/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent"> <textview Android: id = "@ + ID/view1" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: TEXT = "This is the first tab label"/> <textview Android: Id = "@ + ID/view2" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: text = "this is the second tab label"/> <textview Android: Id = "@ + ID/view3" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: text = "this is the third tab label"/> </framelayout>
3. Create a tab activity,
protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setTitle("TabViewDemo"); TabHost tabHost = getTabHost(); LayoutInflater.from(this).inflate(R.layout.tab_demo, tabHost.getTabContentView(),true); tabHost.addTab(tabHost.newTabSpec("Tab1").setIndicator("Tab1"). setContent(R.id.view1)); tabHost.addTab(tabHost.newTabSpec("Tab2")setIndicator("Tab2"). setContent(R.id.view2)); tabHost.addTab(tabHost.newTabSpec("Tab3").setIndicator("Tab3"). setContent(R.id.view3)); }
4. register the tab activity in adroidmanifest. xml.
<activity android:name=".TabViewDemo" android:label="@string/app_view"> </activity>