我想創建標籤沒有擴展TabActivity。 (原因是TabActivity無法像處理自定義標題欄那樣)。我有Android:沒有TabActivity的TabHost
public class startTab extends Activity {
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.mylayout);
Resources res = getResources();
LocalActivityManager mlam = new LocalActivityManager(this, false);
TabHost tabHost = (TabHost) findViewById(R.id.tabhost);
tabHost.setup(mlam);
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, Show1.class);
spec = tabHost.newTabSpec("Items").setIndicator("Items", res.getDrawable(R.drawable.items32_ldpi)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Show2.class);
spec = tabHost.newTabSpec("Users").setIndicator("Users",res.getDrawable(R.drawable.user32_ldpi)).setContent(intent);
tabHost.addTab(spec);
}
}
我得到的是
07-02 07:11:12.715: ERROR/AndroidRuntime(411):
Caused by: java.lang.IllegalStateException: Activities can't be added until the containing group has been created.
的查看XML是
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost" android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:paddingTop="5dip">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="fill_parent"></TabWidget>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:paddingTop="5dip">
</FrameLayout>
</LinearLayout>
</TabHost>
我讀的地方,我必須使用LocalActivityManager錯誤,我認爲我錯過了那裏的一些東西。任何人的想法?
謝謝!
本教程可以幫助你http://learnncode.wordpress.com/2013/12/18/how-to-use-tabwidget-with-fragments/ – Prachi 2013-12-23 11:45:37