views:

252

answers:

1

I have an app with 2 tabs, the first is a listview, and the second I'm trying to make a TextView. The problem is I have no idea on how to get the TextView to show up. The listview is working, but I can't get anything on the TextView at all. I tried using the Hello, World to try to work with the text into the tab, but I can't figure it out.

My main.xml section with the TabWidget looks like this:

    <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">
            <ListView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:id="@+id/itemlist" />
            <TextView 
                android:id="@+id/HelloAndroid"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"/>
        </FrameLayout>

ListView is being used on the java file with the mTabHost code,

        TabHost mTabHost = getTabHost();

    mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("Answer").setContent(R.id.itemlist));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("Ask").setContent(R.id.HelloAndroid));

    mTabHost.setCurrentTab(0);
}

The TextView is on a different file called HelloAndroid.java, and the code looks like:

public class HelloAndroid extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       TextView tv = new TextView(this);
       tv.setText("Hello, Android");
       setContentView(tv);
   }
}

How can I fix it so that the 2nd tab brings up the example text? Thanks!

+2  A: 

Hi
If I understand correctly you want to display the HelloAndroid activity as a content of second tab. If I'm right, instead of this:


    mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("Ask").setContent(R.id.HelloAndroid));
 

you should call this:


 Intent i = new Intent(this, HelloAndroid.class);
 mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("Ask").setContent(i));
 

But you have to bear in mind that your HelloAndroid activity has nothing in common with TextView in your layout file. So probably it would be better not to set the activity as a tab content but to change the value of text view from your layout file.

PS. Remember to put your HelloAndroid activity to Manifest.xml

Ramps
This worked great thanks so much!
Tyler