Your content must have a TabHost whose id attribute is ‘android.R.id.tabhost’ 解決

來源:互聯網
上載者:User

問題1. 運行Activity的時候出現Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
添加Layout的時候,xml跟元素選擇TabHost, 但是ADT沒有添加id屬性, 啟動並執行時候,會提示Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'錯誤, 需要添加android:id="@android:id/tabhost", 這樣就可以了。

問題2. 運行Activity的時候出現Your TabHost must have a TabWidget whose id attribute is 'android.R.id.tabcontent'

解決方案: 修改FrameLayout添加id屬性, ADT自動產生的xml檔案中Id是android:id="@+id/FrameLayout01 ", 需要修改成下面的格式android:id="@android:id/tabcontent ",這個估計會困擾一大批初學者,誰會想到會修改這個地方,看到錯誤很容易修改成tabcontent,但是首碼不容易想到。 而且在ADT可視化編輯這個檔案的時候, 介面上顯示NullPointerException,這個是ADT的一個BUG。

xml檔案代碼:

<?xml version="1.0" encoding="utf-8"?><TabHost xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@android:id/tabhost"    android:layout_width="fill_parent"    android:layout_height="fill_parent" >    <LinearLayout        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:orientation="vertical" >        <!-- 實現Tab標籤的居底主要是通過設定屬性 android:layout_weight="1" -->        <!-- 還要注意FrameLayout標籤的位置,要寫在TabWidget標籤的前面 -->        <FrameLayout            android:id="@android:id/tabcontent"            android:layout_width="fill_parent"            android:layout_height="fill_parent"            android:layout_weight="1" />        <TabWidget            android:id="@android:id/tabs"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:layout_alignParentBottom="true" />    </LinearLayout></TabHost>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.