1. Inheriting tabactivity implementations
A) Use Framelayout in the layout file to list the tab component and the content component in the tab
b) activity to inherit tabactivity
c) Call Tabactivity's Gettabhost () method to get the Tabhost object
d) Create tab options with Tabhost
Public classMainactivityextendstabactivity {@Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); /*requestwindowfeature (Window.feature_no_title); GetWindow (). SetFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FU Llscreen);*/tabhost th=Gettabhost (); Layoutinflater.from ( This). Inflate (R.layout.main, Th.gettabcontentview (),true); Th.addtab (Th.newtabspec (' All '). Setindicator ("All Call logs"). SetContent (r.id.textview01)); Th.addtab (Th.newtabspec ("OK"). Setindicator ("Received call"). SetContent (r.id.textview02)); Th.addtab (Th.newtabspec ("Cancel"). Setindicator ("Missed Call"). SetContent (r.id.textview03)); Th.setontabchangedlistener (NewOntabchangelistener () {@Override Public voidontabchanged (String tabId) {toast.maketext (mainactivity. This, TabId, Toast.length_long). Show (); } } ); }}
2. The tab content can also be specified by implementing an interface Tabhost.tabcontentfactory Createtabcontent method.
Public classMainactivityextendsTabactivityImplementsTabhost.tabcontentfactory {/**Called when the activity is first created.*/@Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Tabhost th=Gettabhost (); Th.addtab (Th.newtabspec (' All '). Setindicator ("All call Logs"). SetContent ( This)); Th.addtab (Th.newtabspec ("OK"). Setindicator ("Received call"). SetContent ( This)); Th.addtab (Th.newtabspec ("Cancel"). Setindicator ("Missed Call"). SetContent ( This)); } PublicView createtabcontent (String tag) {ListView LV=NewListView ( This); List<String> list =NewArraylist<string>(); List.add (tag); if(Tag.equals ("All") {List.add ("Tom"); List.add ("Kite"); List.add ("Rose"); }Else if(Tag.equals ("OK") {List.add ("Tom"); List.add ("Kite"); }Else{List.add ("Rose"); } Arrayadapter Adapter=NewArrayadapter ( This, Android. r.layout.simple_list_item_checked, list); Lv.setadapter (adapter); returnLV; }}
<android>tab tab