我想爲我的android應用程序創建一個TabActivity。當我的佈局XML顯示如下,併爲我的2個選項卡顯示虛擬TextView內容時,一切都顯示正常。與TabActivity/TabWidget的Android錯誤
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="3px">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<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="wrap_content"
android:padding="10px">
<TextView android:id="@+id/login_form" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="DUMMY LOGIN FORM" />
<TextView android:id="@+id/register_form" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="DUMMY REGISTER FORM" />
</FrameLayout>
</LinearLayout>
</TabHost>
我想用包含多個View元素的LinearLayout替換每個TextView。 Howevever,如果我嘗試用下面的東西替換TextView行,那麼我立即得到一個Force Close窗口。
<LinearLayout android:id="@+id/login_form" android:layout_width="fill_parent" layout_height="fill_parent" android:orientation="vertical">
<TextView android:id="@+id/username_label" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/username" />
</LinearLayout>
<LinearLayout android:id="@+id/register_form" android:layout_width="fill_parent" layout_height="fill_parent" android:orientation="vertical">
<TextView android:id="@+id/username_desired_label" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/username_desired" />
</LinearLayout>
爲什麼這會使我得到強制關閉?我應該使用除LinearLayout以外的其他視圖來將我的標籤內容分組在一起嗎?
編輯:如果這是有關我的問題,我擴展TabActivity
類,和我onCreate
方法如下所示:
protected void onCreate(Bundle savedInstanceState) {
// display the login/register view
super.onCreate(savedInstanceState);
setContentView(R.layout.login_register);
// associate the tab content with each tab, and specify the tab headers
setDefaultTab(0);
TabHost tabs = getTabHost();
tabs.addTab(tabs.newTabSpec("login").setIndicator(getResources().getText(R.string.login)).setContent(R.id.login_form));
tabs.addTab(tabs.newTabSpec("register").setIndicator(getResources().getText(R.string.register)).setContent(R.id.register_form));
}
編輯:按照要求,這裏的堆棧-trace,並顯示錯誤消息只沿着讀取 「源未找到」。:
螺紋[< 3>主](吊 (異常RuntimeException的)) ActivityThread.performLaunchActivity(ActivityThread $ ActivityRecord, 意圖)線:2401 ActivityThread.handleLaunchActivity(ActivityThread $ ActivityRecord, 意圖)線:2417 ActivityThread.access $ 2100(ActivityThread, ActivityThread $ ActivityRecord,意圖) 線:116 ActivityThread $ H.handleMessage(消息) 線:1794 ActivityThread $ H(處理程序).dispatchMessage(消息) 行:99 Looper.loop()線:123 ActivityThread.main(字符串[])線: 4203 Method.invokeNative(Object, Object [],Class,Class [],Class,int, 布爾)行:不可用[本地 方法] Method.invoke(對象, 對象...)線:521 ZygoteInit $ MethodAndArgsCaller.run() 線:791 ZygoteInit.main(字符串[]) 行: 549 NativeStart.main(String []) line:not available [native method]
什麼是堆棧跟蹤?你可以在這裏發佈嗎? – Bostone 2009-12-15 07:47:00