1 PackageCom.myhost;2 3 ImportAndroid.os.Bundle;4 ImportAndroid.view.LayoutInflater;5 ImportAndroid.widget.TabHost;6 Importandroid.app.TabActivity;7 8 Public classTabhostactivityextendstabactivity {//Extend tabactivity class9 Ten /**Called when the activity is first created.*/ One A @Override - - Public voidonCreate (Bundle savedinstancestate) { the - Super. OnCreate (savedinstancestate); - -Tabhost Tabhost = This. Gettabhost ();//The activity tabhost +Layoutinflater.from ( This). Inflate (R.layout.main,tabhost.gettabcontentview (),true); - +Tabhost.addtab (Tabhost.newtabspec ("Tab1") A. Setindicator ("Tab1", getresources () at . Getdrawable (r.drawable.chartareaup_green)) - . SetContent (R.ID.LINEARLAYOUT1)); - -Tabhost.addtab (Tabhost.newtabspec ("TaB2") -. Setindicator ("TaB2", getresources () - . Getdrawable (r.drawable.home_yellow)) in . SetContent (R.ID.LINEARLAYOUT2)); - toTabhost.addtab (Tabhost.newtabspec ("Tab3") +. Setindicator ("Tab3", getresources () - . Getdrawable (r.drawable.harddrivedownload_red)) the . SetContent (R.ID.LINEARLAYOUT3)); * $Tabhost.addtab (Tabhost.newtabspec ("TAB4")Panax Notoginseng. Setindicator ("Tab4", getresources () - . Getdrawable (r.drawable.shoppingcart_blue)) the . SetContent (R.ID.LINEARLAYOUT4)); + } A}
1 PackageNet.weibo.ui;2 3 Importandroid.app.TabActivity;4 Importandroid.content.Intent;5 ImportAndroid.os.Bundle;6 ImportAndroid.util.Log;7 ImportAndroid.widget.RadioGroup;8 ImportAndroid.widget.RadioGroup.OnCheckedChangeListener;9 ImportAndroid.widget.TabHost;Ten ImportAndroid.widget.TabHost.TabSpec; One A Public classMainactivityextendstabactivity { - /**Called when the activity is first created.*/ - Publictabhost mth; the Public Static FinalString tab_home= "HOME"; - Public Static FinalString tab_msg= "Information"; - Public Static FinalString tab_abt= "About"; - Public Static FinalString tab_seh= "SEARCH"; + Public Static FinalString tab_more= "More"; - + PublicRadiogroup Radiogroup; A at - @Override - Public voidonCreate (Bundle savedinstancestate) { - Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.main); - inMth= This. Gettabhost ();//mth and so on the 18th line of writing. - toTabspec ts1=Mth.newtabspec (tab_home). Setindicator (tab_home); +Ts1.setcontent (NewIntent (mainactivity. This, Firstactivity.class)); - Mth.addtab (TS1); the *Tabspec ts2=Mth.newtabspec (tab_msg). Setindicator (tab_msg); $Ts2.setcontent (NewIntent (mainactivity. This, Secondactivity.class));Panax Notoginseng Mth.addtab (TS2); - the +Tabspec ts3=Mth.newtabspec (TAB_ABT). Setindicator (TAB_ABT); ATs3.setcontent (NewIntent (mainactivity. This, Thirdactivity.class)); the Mth.addtab (TS3); + -Tabspec ts4=Mth.newtabspec (Tab_seh). Setindicator (Tab_seh); $Ts4.setcontent (NewIntent (mainactivity. This, Forthactivity.class)); $ Mth.addtab (TS4); - -Tabspec ts5=Mth.newtabspec (Tab_more). Setindicator (Tab_more); theTs5.setcontent (NewIntent (mainactivity. This, Fifthactivity.class)); - Mth.addtab (TS5);Wuyi the This. radiogroup=(Radiogroup) Findviewbyid (r.id.main_radio); -Radiogroup.setoncheckedchangelistener (NewOncheckedchangelistener () { Wu - @Override About Public voidOnCheckedChanged (Radiogroup Group,intCheckedid) { $ //TODO auto-generated Method Stub - - Switch(checkedid) { - CaseR.id.radio_button0: A + Mth.setcurrenttabbytag (tab_home); the Break; - CaseR.id.radio_button1: $ the Mth.setcurrenttabbytag (tab_msg); the Break; the CaseR.id.radio_button2: the Mth.setcurrenttabbytag (TAB_ABT); - Break; in CaseR.id.radio_button3: the the Mth.setcurrenttabbytag (Tab_seh); About Break; the CaseR.id.radio_button4: the the Mth.setcurrenttabbytag (tab_more); + Break; - } the }Bayi }); the the } -}
The above two kinds of writing method is ripe and inferior?
Androu class Tutorial (5): Thinking of Tabhost