-1

androiddevelopersのWebサイトからのチュートリアルに従っています。コードをコピーしましたが、mTabHostでエラーが発生します。何かをインポートする必要があるかどうかを確認しましたが、すべてがインポートされています。

コード

package com.tabTestx;

import android.app.Activity;
import android.app.TabActivity;
import android.os.Bundle;

public class TabTestXActivity extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mTabHost = getTabHost();

    mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent(R.id.textview1));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2").setContent(R.id.textview2));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("TAB 3").setContent(R.id.textview3));

    mTabHost.setCurrentTab(0);
}
}

誰か助けてください

4

3 に答える 3

1

mTabHost次のように宣言するのを忘れますTabHost

TabHost mTabHost = getTabHost(); //declare as TabHost in your code
^^^^^^^   
于 2012-06-07T14:03:51.193 に答える
1

xml に android:id/tabhost がありますか?

      <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

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

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:layout_marginTop="5dp"
                android:background="@drawable/rounded_border"/>

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" 
                android:background="@android:color/white">


            </FrameLayout>
        </LinearLayout>
    </TabHost>
于 2012-06-07T14:03:53.957 に答える
1

このように、TabHost をインポートします。

TabHost mTabHost = getTabHost(); 

詳細については、次のリンクを参照ください。 -android.html

于 2012-06-07T14:05:16.997 に答える