The Tab.xml code is as follows:
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Fill_parent "android:layout_height=" fill_parent "android:orientation=" vertical "&G T <linearlayout android:id= "@+id/tab_1" android:layout_width= "Wrap_content" android:layout_height= "W Rap_content "android:orientation=" vertical "> <chronometer android:id=" @+id/mychronometer " Android:layout_width= "Wrap_content" android:layout_height= "wrap_content"/> <button Android:id= "@+id/btnstart" android:layout_width= "wrap_content" android:layout_height= "Wrap_c Ontent "android:text=" Start timing "/> <button android:id=" @+id/btnstop "Android:lay Out_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "Stop timing"/> <b Utton android:id= "@+id/btnbase "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "an droid:text= "reset"/> <button android:id= "@+id/btnformat" android:layout_width= "Wrap_conte NT "android:layout_height=" Wrap_content "android:text=" formatted display "/> </LinearLayout> < LinearLayout android:id= "@+id/tab_2" android:layout_width= "wrap_content" android:layout_height= "Wrap_ Content "android:orientation=" vertical "> <analogclock android:layout_width=" wrap_content " android:layout_height= "Wrap_content"/> </LinearLayout> <linearlayout android:id= "@+id /tab_3 "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "android:orientation= "Horizontal" > <button android:id= "@+id/btnstart" android:layout_width= "Wrap_content" Android:layout_height= "Wrap_content" android:text= "Start timing"/> <button android:id= "@+id/btnstop" Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "Stop Timing"/&G T <button android:id= "@+id/btnbase" android:layout_width= "Wrap_content" Android:layout_h eight= "Wrap_content" android:text= "reset"/> <button android:id= "@+id/btnformat" Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "formatted display"/> ; </LinearLayout></LinearLayout>
. Java code is as follows:
Package Org.lxh.demo;import Android.app.activity;import Android.app.tabactivity;import android.os.Bundle;import Android.os.systemclock;import Android.view.layoutinflater;import Android.view.view;import Android.view.view.onclicklistener;import Android.view.view.onfocuschangelistener;import Android.widget.Button; Import Android.widget.chronometer;import Android.widget.edittext;import Android.widget.tabhost;import Android.widget.tabhost.tabspec;import Android.widget.textview;public class Hello extends Tabactivity {// Inherit Tabhost class private Tabhost mytabhost;private int[] layres={r.id.tab_1,r.id.tab_2,r.id.tab_3};p ublic void OnCreate ( Bundle savedinstancestate) {super.oncreate (savedinstancestate);//life cycle Method This.mytabhost=super.gettabhost (); Layoutinflater.from (This). Inflate (R.layout.tab, This.myTabHost.getTabContentView (), true); for (int x=0;x< this.layres.length;x++) {tabspec mytab=mytabhost.newtabspec ("tab" +x); Mytab.setindicator ("label" +x); myTab.setContent (This.layres[x]); This.myTabHost.addTab (Mytab);}}}
The results are as follows:
android--Label component (Tabhost) Small instance