替代使用一个活动为每个标签 [英] Alternatives to using an activity for each tab
问题描述
本之情况是这样的。目前我使用下面的code
The scenerio is like this. Currently I am using the following code
TabSpec setContent = tabhost.newTabSpec("tab")
.setIndicator("tabview")
.setContent(new Intent(tabhost.getContext(), someActivity.class));
不过,据我所知,每个选项卡不应该与活动相关联,我们必须遵循code这样的事情。
But I am told that each tab should not be associated with an activity and we must follow code something like this.
TabSpec setContent = tabhost.newTabSpec("tab").setIndicator("tabView").setContent(R.id.layout)
考虑这样一个场景,TAB1调用摄像头的应用程序,TAB2解析XML和TAB3做一些其他的显示工作。我该如何解决这个问题?因为一旦标签被改变,我必须调用这些方法。如何创建一个单一的活动,将所有的责任呢?
Consider a scenario where tab1 calls camera app, tab2 parses an XML and tab3 does some other display work. How do I solve this ? Because as soon as tab is changed I must call these methods. How do I create a single activity and assign all responsibilities to it ?
推荐答案
您可以创建仅显示标签看法单个活动。唯一的缺点是,意见必须在标签中定义。
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.
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@+id/list1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<ListView
android:id="@+id/list2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
</FrameLayout>
然后,当你TabActivity您的onCreate里面:
Then, when inside your onCreate in your TabActivity:
TabHost tabs = getTabHost();
TabHost.TabSpec commentsTab = tabs.newTabSpec(TAB_TAG_1);
tabs.addTab(commentsTab.setContent(R.id.list1));
TabHost.TabSpec infoTab = 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.
这篇关于替代使用一个活动为每个标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!