tags:

views:

293

answers:

1

I am using the following code to setup a TabWidget:

 public void onCreate(Bundle savedInstanceState) {    
        super.onCreate(savedInstanceState);    
        setContentView(R.layout.main);    
        TabHost mTabHost = getTabHost();  

        mTabHost.addTab(mTabHost.newTabSpec("tab_1").setIndicator("Tab1", getResources().getDrawable(R.drawable.tab_1)).setContent(new Intent(this, TabClass1.class)));
        mTabHost.addTab(mTabHost.newTabSpec("tab_2").setIndicator("Tab2", getResources().getDrawable(R.drawable.tab_2)).setContent(new Intent(this, TabClass2.class)));      
        mTabHost.addTab(mTabHost.newTabSpec("tab_3").setIndicator("Tab3", getResources().getDrawable(R.drawable.tab_3)).setContent(new Intent(this, TabClass3.class)));        
        mTabHost.setCurrentTab(0);          
    }

So, TabClass1, TabClass2 and TabClass3 are separate .java files that are contained within my package. I am able to create content within each of these .java files and display the content when each tab is selected - but how do I assign an XML layout file to each of the .java files?

I have tried various setups but have been unable to create a TextView in an XML Layout and have it display when a particular tab is selected.

A: 

ok in your TabClass1.class you must have somethin like

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mycontentA);        
}

your Layout myContentA.xml must be similar to...

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/layout"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
<TextView
        android:id="@+id/myTextView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"     
        android:ellipsize="marquee"
        android:singleLine="true"        
        android:textStyle="bold"
        android:textColor="#000000">
</LinearLayout>

you will reuse this xml layout in TabClass2.class and TabClass3.class or create myContentB.xml and myContentC.xml

Jorgesys
That is what I needed. Thank You.
Chris