(重要部分のみ...):ここでは
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tWelcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/bNewTask"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Task" />
<TabHost
android:id="@+id/myTabs"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
</LinearLayout>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/tTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
が今の私の活動コードです:
だからここに私のXMLです。
TabActivityを使用している場合(要件ではないが、作業が楽になる場合)、タブホストのIDはandroid:id="@android:id/tabhost"
でなければなりません。
私はタブーホストがルートノードでなければならないとも言いました。私はアンドロイドのドキュメントを使用して確認できません。私はおそらく、他のすべての道が失敗した(または誰かがそれが真実であることを確認した)後、この変更を行うだろう。
TabActivityを使用している場合は、idでタブホストを参照する必要はなく、setup()メソッドを使用することもできます。私はあなたがsetup()メソッドを使用しているのを見ていますが、あなたの活動がTabActivityであるかどうかはわかりません。もしそうなら、あなたの問題を引き起こしているかもしれません。
以下は、私がタブレイアウトの設定に使用する方法です。それは私のために働きます。これはレイアウトのルートノードとしてタブホストを想定しており、それはidとしてandroid:id/tabhost
を持ち、TabActivityです。
tabhostコード:
public class Tabs extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_layout);
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
spec = tabHost.newTabSpec("tag1").setIndicator("All").setContent(R.id.tab1);
tabHost.addTab(spec);
spec = tabHost.newTabSpec("tag2").setIndicator("Personal").setContent(R.id.tab2);
tabHost.addTab(spec);
}
}
・ホープ、このことができます! (問題を解決する場合は、必ず答えを受け入れるためにチェックマークをクリックしてください)。
あなたが代わりに '' TabHost'のTabLayout'を使用しない理由は? –