程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> radiogroup-求大神看一下哪裡錯了,急急急急

radiogroup-求大神看一下哪裡錯了,急急急急

編輯:編程綜合問答
求大神看一下哪裡錯了,急急急急

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'爆這個錯

最佳回答:


tabhost 沒有綁定 id名哦,所以
android:id="@+id/tabhost" 這句話 找id是tabhost 的 找不到

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved