layout_weight">1.0
[4]src/.andyidea.tabdemo包下面各个UI界面类源码:
MainTabActivity.java源码:
[html]
package.andyidea.tabdemo;
importandroid.app.TabActivity;
importandroid.content.Intent;
importandroid.os.Bundle;
importandroid.view.Window;
importandroid.widget.CompoundButton;
importandroid.widget.RadioButton;
importandroid.widget.CompoundButton.OnCheckedChangeListener;
importandroid.widget.TabHost;
publicclassMainTabActivityextendsTabActivityimplementsOnCheckedChangeListener{
privateTabHostmTabHost;
privateIntentmAIntent;
privateIntentmBIntent;
privateIntentmCIntent;
privateIntentmDIntent;
privateIntentmEIntent;
/**Calledwhentheactivityisfirstcreated.*/
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.maintabs);
this.mAIntent=newIntent(this,AActivity.class);
this.mBIntent=newIntent(this,BActivity.class);
this.mCIntent=newIntent(this,CActivity.class);
this.mDIntent=newIntent(this,DActivity.class);
this.mEIntent=newIntent(this,EActivity.class);
((RadioButton)findViewById(R.id.radio_button0))
.setOnCheckedChangeListener(this);
((RadioButton)findViewById(R.id.radio_button1))
.setOnCheckedChangeListener(this);
((RadioButton)findViewById(R.id.radio_button2))
.setOnCheckedChangeListener(this);
((RadioButton)findViewById(R.id.radio_button3))
.setOnCheckedChangeListener(this);
((RadioButton)findViewById(R.id.radio_button4))
.setOnCheckedChangeListener(this);
setupIntent();
}
@Override
publicvoidonCheckedChanged(CompoundButtonbuttonView,booleanisChecked){
if(isChecked){
switch(buttonView.getId()){
caseR.id.radio_button0:
this.mTabHost.setCurrentTabByTag("A_TAB");
break;
caseR.id.radio_button1:
this.mTabHost.setCurrentTabByTag("B_TAB");
break;
caseR.id.radio_button2:
this.mTabHost.setCurrentTabByTag("C_TAB");
break;
caseR.id.radio_button3:
this.mTabHost.setCurrentTabByTag("D_TAB");
break;
caseR.id.radio_button4:
this.mTabHost.setCurrentTabByTag("MORE_TAB");
break;
}
}
}
privatevoidsetupIntent(){
this.mTabHost=getTabHost();
TabHostlocalTabHost=this.mTabHost;
localTabHost.addTab(buildTabSpec("A_TAB",R.string.main_home,
R.drawable.icon_1_n,this.mAIntent));
localTabHost.addTab(buildTabSpec("B_TAB",R.string.main_news,
R.drawable.ic