Skip to content Skip to sidebar Skip to footer

Alternatives To Using An Activity For Each Tab

The scenerio is like this. Currently I am using the following code TabSpec setContent = tabhost.newTabSpec('tab') .setIndicator('tabview') .setConte

Solution 1:

You can create a single activity with tabs that show only views. The only catch is that the views have to be defined inside the tag.

<FrameLayoutandroid:id="@android:id/tabcontent"android:layout_width="fill_parent"android:layout_height="fill_parent"><ListViewandroid:id="@+id/list1"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1"/><ListViewandroid:id="@+id/list2"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1" /></FrameLayout>

Then, when inside your onCreate in your TabActivity:

TabHosttabs= getTabHost();
TabHost.TabSpeccommentsTab= tabs.newTabSpec(TAB_TAG_1);
tabs.addTab(commentsTab.setContent(R.id.list1));

TabHost.TabSpecinfoTab= tabs.newTabSpec(TAB_TAG_2);
tabs.addTab(infoTab.setContent(R.id.list2));

Note that I did not specify indicators for either tab, in the interests of space.

Post a Comment for "Alternatives To Using An Activity For Each Tab"