package com.example.my_weixin;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TabWidget;
public class MainActivity extends TabActivity {
RadioGroup rg01;
RadioButton xx01,txl01,fx01,wo01;
TabHost tabhost;
TabWidget tabwidget;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_main);
init();
TabSpec tabspec01 = tabhost.newTabSpec("tag01");//消息标签
tabspec01.setIndicator("消息");
Intent intent01 = new Intent(MainActivity.this,Activity_XX.class);
tabspec01.setContent(intent01);
tabhost.addTab(tabspec01);
TabSpec tabspec02 = tabhost.newTabSpec("tag02");//通讯录标签
tabspec02.setIndicator("通讯录");
Intent intent02 = new Intent(MainActivity.this,Activity_TXL.class);
tabspec02.setContent(intent02);
tabhost.addTab(tabspec02);
TabSpec tabspec03 = tabhost.newTabSpec("tag03");//发现标签
tabspec03.setIndicator("发现");
Intent intent03 = new Intent(MainActivity.this,Activity_FX.class);
tabspec03.setContent(intent03);
tabhost.addTab(tabspec03);
TabSpec tabspec04 = tabhost.newTabSpec("tag04");//我的标签
tabspec04.setIndicator("我的");
Intent intent04 = new Intent(MainActivity.this,Activity_Wo.class);
tabspec04.setContent(intent04);
tabhost.addTab(tabspec04);
rg01.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {//那个单选钮被点击了。arg1就是那个单选钮
switch(arg1){
case R.id.xx:
tabhost.setCurrentTab(0);
break;
case R.id.txl:
tabhost.setCurrentTab(1);
break;
case R.id.fx:
tabhost.setCurrentTab(2);
break;
case R.id.wo:
tabhost.setCurrentTab(3);
break;
}
}});
}
public void init(){
tabhost = getTabHost();
tabwidget = tabhost.getTabWidget();
rg01 = (RadioGroup) findViewById(R.id.rg);
xx01 = (RadioButton) findViewById(R.id.xx);
txl01 = (RadioButton) findViewById(R.id.txl);
fx01 = (RadioButton) findViewById(R.id.fx);
wo01 = (RadioButton) findViewById(R.id.wo);
}
}