Hello, TabWidget each tab refer to new xml

Posted by Clozecall on Stack Overflow See other posts from Stack Overflow or by Clozecall
Published on 2011-01-06T01:34:27Z Indexed on 2011/01/06 1:54 UTC
Read the original article Hit count: 550

Filed under:
|
|
|
|

Hey everyone I'm using Google's exmaple of Hello, TabWidget but altered it to look like this:

main.xml:

<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">
        <TextView 
            android:text="@+layout/text"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
        <TextView 
            android:id="@+id/textview2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" 
            android:text="this is another tab" />
        <TextView 
            android:id="@+id/textview3"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" 
            android:text="this is a third tab" />
    </FrameLayout>
</LinearLayout>

java file:

public class HelloTabWidget extends TabActivity {

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);

TabHost mTabHost = getTabHost();

mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent(R.layout.text));
mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2").setContent(R.id.textview2));
mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("TAB 3").setContent(R.id.textview3));

mTabHost.setCurrentTab(0);

} }

and here is the text.xml in res/layout:

<LinearLayout
    android:id="@+id/LinearLayout01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android" >

    <TextView
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:text="This is Tab 1" />

What I'm basically trying to do is have each tab refer to its own xml file rather than all in main.xml, but the text in the first tab doesn't show up.

© Stack Overflow or respective owner

Related posts about android

Related posts about Xml