activity如下:
package com.mobileclient.activity;
import com.mobileclient.app.Declare;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;
public class TeachSourceDetailActivity extends TabActivity implements OnCheckedChangeListener{
private String courseNumber;
private TabHost tabHost;
private RadioGroup radioGroup;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 设置标题
setTitle("手机客户端-课程信息详情");
setContentView(R.layout.source_detail_main);
Declare declare = (Declare) getApplicationContext();
String username = declare.getUserName();
if (username == null) {
setTitle("当前位置--课程信息列表");
} else {
setTitle("您好:" + username + " 当前位置---课程信息列表");
}
radioGroup=(RadioGroup)findViewById(R.id.radiogroup);
radioGroup.setOnCheckedChangeListener(this);
tabHost=(TabHost)findViewById(android.R.id.tabhost);
tabHost.setFocusable(true);
tabHost.setCurrentTab(0);
tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("introduce")
.setIndicator("Introduce")
.setContent(new Intent(this,IntroduceActivity.class)));
tabHost.addTab(tabHost.newTabSpec("chapter").
setIndicator("Chapter").
setContent(new Intent(this,ChapterActivity.class)));
tabHost.addTab(tabHost.newTabSpec("notes").
setIndicator("Notes").
setContent(new Intent(this,NotesActivity.class)));
}
@Override
public void onCheckedChanged(RadioGroup group,int checkedId) {
// TODO Auto-generated method stub
switch (checkedId) {
case R.id.radio_introduce:
this.tabHost.setCurrentTabByTag("introduce");
break;
case R.id.radio_chapter:
this.tabHost.setCurrentTabByTag("chapter");
break;
case R.id.radio_notes:
this.tabHost.setCurrentTabByTag("notes");
break;
}
}
}
tabhost界面:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <FrameLayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="0.0dip" android:layout_weight="1.0"/> <TabWidget android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0.0" android:visibility="gone" /> <RadioGroup android:id="@+id/radiogroup" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:background="@drawable/bottombg" android:gravity="center_vertical" android:orientation="horizontal" > <RadioButton android:id="@+id/radio_introduce" android:layout_height="wrap_content" android:layout_width="wrap_content" android:background="@drawable/introduce" android:button="@null" android:layout_weight="1" android:checked="true" style="@style/rbt_bottom" android:text="@string/introduce"/> <RadioButton android:id="@+id/radio_chapter" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/introduce" android:layout_weight="1" android:button="@null" style="@style/rbt_bottom" android:text="@string/chapter"/> <RadioButton android:id="@+id/radio_notes" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/introduce" android:layout_weight="1" android:button="@null" style="@style/rbt_bottom" android:text="@string/notes" /> </RadioGroup> </LinearLayout> </TabHost>