I'm pretty confused trying to create a tabbed application and could
really use some assistance...
I'm trying to create a layout (main.xml) with 4 tabs, each tab
containing a separate linear layout, which I would like to be able to
define in a separate layout xml file. I've been able to create the 4
tabs, but can't get any content to come up for any of them, just a
blank screen.
I pretty much copied the "Hello, TabWidget" example code from Google's
Android Developers site to get the existing tabs. By the way, I also
can't seem to use the Layout editor to edit main.xml, I can only edit
the xml itself. I can, however, use the layout view for my other
layouts (tab1.xml, tab2.xml, tab3.xml, and tab4.xml).
THANKS FOR ANY ASSISTANCE YOU CAN OFFER!
This is my java code:
public class myProject extends TabActivity {
private TabHost tabHost;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("tab_test1").setIndicator
("Tab 1").setContent(R.layout.tab1));
tabHost.addTab(tabHost.newTabSpec("tab_test2").setIndicator
("Tab 2").setContent(R.layout.tab2));
tabHost.addTab(tabHost.newTabSpec("tab_test3").setIndicator
("Tab 3").setContent(R.layout.tab3));
tabHost.addTab(tabHost.newTabSpec("tab_test4").setIndicator
("Tab 4").setContent(R.layout.tab4));
tabHost.setCurrentTab(0);
}
This is my main.xml:
<?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">
<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:id="@+layout/tab1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<LinearLayout
android:id="@+layout/tab2"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<LinearLayout
android:id="@+layout/tab3"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<LinearLayout
android:id="@+layout/tab4"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
</LinearLayout>
</TabHost>
Here is an example of one of my tab layouts that I can't get to
appear:
<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/TextView01"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="This is Tab 1"></TextView>
</LinearLayout>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---