在代码中,使用的是FrangmentActicity,因为TabActivity已经不能用了,可是每次运行时,应用程序都无法启动,我试了下,好像到了spec = tabhost.newTabSpec("rb_player_local").setIndicator("rb_player_local").setContent(new Intent(this, Test.class));
这句时,程序就执行不下去了,因为后面这句System.out.println("tabhost");一直就没有执行,求各位大神指导指导
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;
}
}
}androidtabhost
这句时,程序就执行不下去了,因为后面这句System.out.println("tabhost");一直就没有执行,求各位大神指导指导
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;
}
}
}androidtabhost
解决方案 »
- 求助
- android view的setVisibility的方法
- 初学android,创建工作报错
- 自带的LatinIME,按下虚拟键盘上的某个按键,会弹出popupwindow,调用的是什么函数
- ViewFlipper切换图片的一些问题
- 请教:getSharedPreferences的参数MODE_PRIVATE
- android开发 使用系统图片浏览器浏览图片问题
- sdk manager 无法更新
- Android中Eclipse错误You must restart adb and Eclipse.
- 想做一个APP页面,同时预览USB摄像头,和手机自带摄像头
- getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS) 会返回null的问题
- eclipse中写了一个安卓应用,相同的代码在不同的project显示不同结果,这是为什么?
看看AndroidManifest.xml文件中有没有注册Test这个Activity。
<?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>
那不是这个问题,不妨贴Log出来看看。