关于TabHost addTab的问题

kaka_answer 2013-03-01 01:39:07
在代码中,使用的是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;
}

}

}
...全文
380 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xun-ming 2013-06-07
  • 打赏
  • 举报
回复
lz的问题解决了吗,没解决的话把log贴出来给大家看看啊,我以前也用的tabActivity
顾小林 2013-03-09
  • 打赏
  • 举报
回复
错了 我是用的这个 TabActivity
顾小林 2013-03-09
  • 打赏
  • 举报
回复
mTabHost = getTabHost(); 这么获取你那个 tabHost 试试看
magong 2013-03-08
  • 打赏
  • 举报
回复
抱歉,好长时间没上网。 那不是这个问题,不妨贴Log出来看看。
kaka_answer 2013-03-02
  • 打赏
  • 举报
回复
???? 求指导啊
kaka_answer 2013-03-01
  • 打赏
  • 举报
回复
我加了的,可是还是不行啊。。。
<?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>
magong 2013-03-01
  • 打赏
  • 举报
回复
引用 楼主 kaka_answer 的回复:
在代码中,使用的是FrangmentActicity,因为TabActivity已经不能用了,可是每次运行时,应用程序都无法启动,我试了下,好像到了spec = tabhost.newTabSpec("rb_player_local").setIndicator("rb_player_local").setContent(new Intent(this, Test.class)); 这句时,程序就执行不下去了
这一句中可能出问题的就是new Intent(this, Test.class) 看看AndroidManifest.xml文件中有没有注册Test这个Activity。

80,362

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧