开发者

Android error with TabActivity / TabWidget

I'm trying to create a TabActivity for my android application. When my layout XML appears as follows with dummy TextView content for my 2 tabs, everything appears fine.

<?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>

I'd like to replace each TextView with a LinearLayout that contains multiple View elements. Howevever, if I try to replace the TextView lines with something like the following, then I immediately get a Force Close window.

<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>

Why would this cause me to get a Force Close? Should I be using a different View other than LinearLayout to group my tab contents together?

Edit: In case it is relevant to my issue, I am extending the TabActivity class, and my onCreate method looks like the following:

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.newTa开发者_StackOverflow中文版bSpec("register").setIndicator(getResources().getText(R.string.register)).setContent(R.id.register_form));
}

Edit: As requested, here's the stack-trace, along with an error message reading only "Source not found.":

Thread [<3> main] (Suspended (exception RuntimeException)) ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2401 ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2417 ActivityThread.access$2100(ActivityThread, ActivityThread$ActivityRecord, Intent) line: 116 ActivityThread$H.handleMessage(Message) line: 1794 ActivityThread$H(Handler).dispatchMessage(Message) line: 99 Looper.loop() line: 123 ActivityThread.main(String[]) line: 4203 Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] Method.invoke(Object, Object...) line: 521 ZygoteInit$MethodAndArgsCaller.run() line: 791 ZygoteInit.main(String[]) line: 549 NativeStart.main(String[]) line: not available [native method]


Wow, I'm an idiot. In my LinearLayout declarations, they both included layout_height attributes instead of required android:layout_height attributes. Stupid oversight on my part, I won't be making that mistake again.

Thanks for taking the time to look, DroidIn.net.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜