jHogen
jHogen

Reputation: 123

Set multiple items inside a tab off Android's Tabhost

For the app I'm working on I'd like to have 3 tabs with different elements in them. I tried searching for a way to accomplish this but I can't seem to find an example of what I need.

Basicly I want this:

Tab 1, contains 4 buttons and a textview

Tab 2, contains an scrollable imageview

Tab 3, contains an webview

I would like to solve this problem without the use of activity's because all 3 tabs need to access the same data.

Currently I use this xml as layout:

<?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">
<LinearLayout
    android:orientation="vertical"
    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" />
    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/photoLayout">
            <Button
                android:text="@string/photoButton"
                android:layout_column="0"
                android:id="@+id/photoButton"
                android:textSize="10dp" />
            <Button
                android:text="@string/locateButton"
                android:layout_column="1"
                android:id="@+id/locateButton"
                android:textSize="10dp" />
            <Button
                android:text="@string/cropButton"
                android:layout_column="2"
                android:id="@+id/cropButton"
                android:textSize="10dp" />
            <Button
                android:text="reset"
                android:layout_column="3"
                android:id="@+id/resetButton"
                android:textSize="10dp" />
            <ScrollView
                android:minWidth="25px"
                android:minHeight="25px"
                android:layout_width="fill_parent"
                android:layout_height="370dp"
                android:id="@+id/scrollView1"
                android:fillViewport="true">
                <TextView
                    android:text="Text"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:id="@+id/textView1" />
            </ScrollView>
        </LinearLayout>
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/webviewLayout">
            <WebView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:id="@+id/webView1" />
        </LinearLayout>
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/imageLayout">
            <ScrollView
                android:minWidth="25px"
                android:minHeight="25px"
                android:layout_width="fill_parent"
                android:layout_height="412dp"
                android:id="@+id/scrollView2"
                android:fillViewport="true">
                <ImageView
                    android:src="@android:drawable/ic_menu_gallery"
                    android:layout_column="0"
                    android:id="@+id/imageView1"
                    android:layout_height="411.6dp"
                    android:layout_width="316.7dp"
                    android:scaleType="centerInside" />
            </ScrollView>
        </LinearLayout>
    </FrameLayout>
</LinearLayout>

The problem with this is that I get a runtime exception saying:

Java.Lang.RuntimeException: Binary XML file line #1: You must supply a layout_width attribute.

Any help to solve this issue will be appreciated!

Upvotes: 0

Views: 368

Answers (1)

Chor Wai Chun
Chor Wai Chun

Reputation: 3236

To answer the exception thrown, you need to specify layout_width and layout_height in every single elements you declared, which in your case, you did not specify any on those buttons.

But to express my curiosity, I believe you should anyhow make it in separate activities and separate layouts, "same data" can always be passed around using some extras I believe.

Upvotes: 1

Related Questions