0

私は Android プログラミングが初めてで、作業を確認するには上級ユーザーが必要です。何らかの理由で、このアプリを実行すると、必要な 2 つのタブの代わりに空白の画面が表示されます。どうもありがとう!

MainActivity.java

package com.example.storeitemfinder3;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
        tabHost.setup();

        TabSpec spec1=tabHost.newTabSpec("Tab 1");
        spec1.setContent(R.layout.tab1);
        spec1.setIndicator("Tab 1");

        TabSpec spec2=tabHost.newTabSpec("Tab 2");
        spec2.setIndicator("Tab 2");
        spec2.setContent(R.layout.tab2);

        tabHost.addTab(spec1);
        tabHost.addTab(spec2);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }



}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tabHost"
    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" />

    <include layout="@layout/tab1" />

    <include layout="@layout/tab2" />

</TabHost>

tab1.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <CheckBox
        android:id="@+id/Avocados"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Avocados" />

    <CheckBox
        android:id="@+id/Cashew_Nuts"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Cashew_Nuts"

        />
 ////android:checked="true"

</LinearLayout>

tab2.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.81"
        android:src="@drawable/tjs" />

</LinearLayout>
4

2 に答える 2

1

これはドキュメントから取得されます:

タブ付きウィンドウ ビューのコンテナー。このオブジェクトは、ユーザーが特定のタブを選択するためにクリックする一連のタブ ラベルと、そのページのコンテンツを表示する FrameLayout オブジェクトの 2 つの子を保持します。個々の要素は通常、子要素自体に値を設定するのではなく、このコンテナー オブジェクトを使用して制御されます。

FrameLayoutの子として1 つ持つ必要があります。TabHost

于 2013-09-08T04:42:52.623 に答える