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

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

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条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀