public class TMainTabActivity extends TabActivity
implements
OnCheckedChangeListener {
RadioGroup radioGroup;
RadioButton[] radioButtons;
TabHost tabHost;
Intent weiboIntent;
Intent messageIntent;
Intent infoIntent;
Intent searchIntent;
Intent moreIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.mytab);
tabHost = getTabHost();
radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
weiboIntent = new
Intent(MyWeiboActivity.INTENT_ACTION_FOR_MYHOME);
messageIntent = new Intent(TMainTabActivity.this,
MessageActivity.class);
infoIntent = new Intent(TMainTabActivity.this,
UserInfoActivity.class);
searchIntent = new Intent(TMainTabActivity.this,
SearchActivity.class);
moreIntent = new Intent(TMainTabActivity.this,
MoreActivity.class);
initButton();
setUpIntent();
radioButtons[tabHost.getCurrentTab()].setChecked(true);
}
private void setUpIntent() {
// TODO Auto-generated method stub
tabHost.clearAllTabs();
tabHost.addTab(tabHost.newTabSpec("tab01").setIndicator("tab")
.setContent(weiboIntent));
tabHost.addTab(tabHost.newTabSpec("tab02").setIndicator("tab")
.setContent(messageIntent));
tabHost.addTab(tabHost.newTabSpec("tab03").setIndicator("tab")
.setContent(infoIntent));
tabHost.addTab(tabHost.newTabSpec("tab04").setIndicator("tab")
.setContent(searchIntent));
tabHost.addTab(tabHost.newTabSpec("tab05").setIndicator("tab")
.setContent(moreIntent));
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
tabHost.setCurrentTab(0);
radioButtons[tabHost.getCurrentTab()].setChecked(true);
}
protected void onResume() {
super.onResume();
}
private void initButton() {
// TODO Auto-generated method stub
radioButtons = new RadioButton[5];
for (int i = 0; i < 5; i++) {
radioButtons[i] = (RadioButton) radioGroup
.findViewWithTag("radio_button" + i);
radioButtons[i].setOnCheckedChangeListener(this);
}
}
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
if (isChecked && tabHost !=
null) {
if (buttonView == radioButtons[0]) {
tabHost.setCurrentTabByTag("tab01");
} else if (buttonView == radioButtons[1]) {
tabHost.setCurrentTabByTag("tab02");
} else if (buttonView == radioButtons[2]) {
tabHost.setCurrentTabByTag("tab03");
} else if (buttonView == radioButtons[3]) {
tabHost.setCurrentTabByTag("tab04");
} else if (buttonView == radioButtons[4]) {
tabHost.setCurrentTabByTag("tab05");
}
}
}
}