80,362
社区成员
发帖
与我相关
我的任务
分享
import android.os.Bundle;
import android.app.Activity;
import android.app.LocalActivityManager;
import android.content.Intent;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;
public class MainActivity extends FragmentActivity implements OnCheckedChangeListener{
private TabHost tabhost;
private RadioGroup rg_player_control;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tabhost_list);
//绑定tabhost
tabhost = (TabHost)findViewById(android.R.id.tabhost);
tabhost.setup();
//radiogroup操作
rg_player_control = (RadioGroup)findViewById(R.id.music_tab_group);
rg_player_control.setOnCheckedChangeListener(this);
rg_player_control.setClickable(true);
TabHost.TabSpec spec;
spec = tabhost.newTabSpec("rb_player_local").setIndicator("rb_player_local").setContent(new Intent(this, Test.class));
System.out.println("tabhost");
tabhost.addTab(spec);
spec = tabhost.newTabSpec("rb_player_favorite").setIndicator("rb_player_favorite").setContent(new Intent(this, Test2.class));
tabhost.addTab(spec);
spec = tabhost.newTabSpec("rb_player_online").setIndicator("rb_player_online").setContent(new Intent(this, Test3.class));
tabhost.addTab(spec);
}
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
switch(checkedId)
{
case R.id.rb_player_local:
tabhost.setCurrentTabByTag("rb_player_local");
break;
case R.id.rb_player_favorite:
tabhost.setCurrentTabByTag("rb_player_favorite");
break;
case R.id.rb_player_online:
tabhost.setCurrentTabByTag("rb_player_online");
break;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mymusic"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.mymusic.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.mymusic.Test"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.example.mymusic.Test2"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.example.mymusic.Test3"
android:label="@string/app_name" >
</activity>
</application>
</manifest>