天妒小时光 2015-01-23 07:33 采纳率: 11.1%
浏览 1722
已采纳

求大神看一下哪里错了,急急急急

xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:ignore="HardcodedText" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="0.0dip"
        android:layout_weight="1.0" />

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.0"
        android:visibility="gone" />

    <RadioGroup
        android:id="@+id/rg_bottom"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:gravity="center"
        android:orientation="horizontal" >

        <RadioButton
            android:id="@+id/shouYe"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:button="@null"
            android:checked="true"
            android:drawableBottom="@drawable/select_shouye"
            android:textColor="#ffffffff" />

        <RadioButton
            android:id="@+id/sheQuZhuanTi"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:button="@null"
            android:drawableBottom="@drawable/select_sqzhuanti"
            android:gravity="center"
            android:textColor="#ffffffff" />

        <RadioButton
            android:id="@+id/sheQuFengCai"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:button="@null"
            android:drawableBottom="@drawable/select_sqfengcai"
            android:gravity="center"
            android:textColor="#ffffffff" />

        <RadioButton
            android:id="@+id/woDeSheQu"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:button="@null"
            android:drawableBottom="@drawable/select_mysq"
            android:gravity="center"
            android:textColor="#ffffffff" />
    </RadioGroup>
</LinearLayout>

 package caifu.life.ZhSQ;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.Toast;

public class MainActivity extends TabActivity  {
    // 退出程序的量
    private long exitTime = 0;

    public static TabHost mTabHost;
    public static TabHost getmTabHost() { 
        return mTabHost; 
    } 
     private RadioGroup gr_bottom; 
     private RadioButton tab_shouYe, tab_zuanTi, tab_fengCai,tab_mine; 

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //不要窗口标题
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        mTabHost = getTabHost();
        final TabWidget tabWidget = mTabHost.getTabWidget(); 
         tabWidget.setStripEnabled(false);// 圆角边线不启用 
        //添加n个tab选项卡,定义他们的tab名,指示名,目标屏对应的类 
         mTabHost.addTab(mTabHost.newTabSpec("shouye").setIndicator("0")
                 .setContent(new Intent(this, ShouYeActivity.class))); 
            mTabHost.addTab(mTabHost.newTabSpec("zuanti").setIndicator("1")
                    .setContent(new Intent(this, ZhuanTiActivity.class))); 
            mTabHost.addTab(mTabHost.newTabSpec("fengcai").setIndicator("2")
                    .setContent(new Intent(this, FengCaiActivity.class))); 
            mTabHost.addTab(mTabHost.newTabSpec("mine").setIndicator("3")
                    .setContent(new Intent(this, MineActivity.class))); 

            gr_bottom = (RadioGroup)findViewById(R.id.rg_bottom);
            tab_shouYe = (RadioButton)findViewById(R.id.shouYe);
            tab_zuanTi = (RadioButton)findViewById(R.id.sheQuZhuanTi);
            tab_fengCai = (RadioButton)findViewById(R.id.sheQuFengCai);
            tab_mine = (RadioButton)findViewById(R.id.woDeSheQu);

            gr_bottom.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { 
                public void onCheckedChanged(RadioGroup group, int id) { 
                    if (id == tab_shouYe.getId()) { 
                        mTabHost.setCurrentTab(0); 
                    } else if (id == tab_zuanTi.getId()) { 
                        mTabHost.setCurrentTab(1); 
                    } else if (id == tab_fengCai.getId()) { 
                        mTabHost.setCurrentTab(2); 
                    } else if (id == tab_mine.getId()) { 
                        mTabHost.setCurrentTab(3); 
                    } 
                } 
            }); 
            //设置当前显示哪个标签
            mTabHost.setCurrentTab(0);


    }






    // 再按一次退出程序
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK
                && event.getAction() == KeyEvent.ACTION_DOWN) {
            if ((System.currentTimeMillis() - exitTime) > 2000) {
                Toast.makeText(getApplicationContext(), "再按一次退出程序",
                        Toast.LENGTH_SHORT).show();
                exitTime = System.currentTimeMillis();
            } else {
                finish();
                // 返回桌面操作
                Intent home = new Intent(Intent.ACTION_MAIN);
                home.addCategory(Intent.CATEGORY_HOME);
                startActivity(home);
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }




}
求大神看一下哪里错了

Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'爆这个错

  • 写回答

2条回答 默认 最新

  • lizhejin1209 2015-01-23 07:41
    关注

    tabhost 没有绑定 id名哦,所以
    android:id="@+id/tabhost" 这句话 找id是tabhost 的 找不到

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗