質問

私が使っているGoogleの例の こんにちは,TabWidget が変化していれば次のようになるはずです:

main.xml:

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <TextView 
                android:text="@+layout/text"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" />
            <TextView 
                android:id="@+id/textview2"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" 
                android:text="this is another tab" />
            <TextView 
                android:id="@+id/textview3"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" 
                android:text="this is a third tab" />
        </FrameLayout>
    </LinearLayout>
</TabHost>

javaファイル:

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

        TabHost mTabHost = getTabHost();

        mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent(R.layout.text));
        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);
    }
}

こちらはtext.xml にres/レイアウト:

<LinearLayout
    android:id="@+id/LinearLayout01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android" >

    <TextView
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:text="This is Tab 1" />
</LinearLayout>

僕は基本的にいって違いますので、それぞれのタブを参照して独自のxmlファイルではなくすべてmain.xmlが、テキストの最初のタブで表示しません。

役に立ちましたか?

解決

あなたは自身のActivityを参照してください。各タブを持ってしようとしていますか?もしそうなら、あなたは各タブの内容として意図設定することができます:

intent = new Intent().setClass(this, Test.class);       
spec = tabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent(intent);
        tabHost.addTab(spec);

もちろん、あなたはその後、セットはレイアウトとしてtest.xmlことをテスト(または任意の他)という名前のクラスを持っていなければならないと思います。

public class Test extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test);
    }
}
これがあれば、

このチュートリアルには、さらにあなたを助けますあなたが設定しようとしていることをシナリオの種類ます。

他のヒント

あつのオプションでタブ内蔵タブます。

  1. 複数のビューを一つの活動の一つのレイアウトファイル
  2. 複数の活動
  3. カスタムビューに構築されTabContentFactory

そのようにしたい#3.何だようこ:

setContent(new TabHost.TabContentFactory() {
    public View createTabContent(String tag)
    {
        View view = LayoutInflater.from(HelloTabWidget.this).inflate(R.layout.text);
        // Setup the view here
        return view;
    }});
View view = LayoutInflater.from(HelloTabWidget.this).inflate(R.layout.text);
LayoutInflater.inflateは、2つのパラメータを取りとして非常に適切ではありません。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top