android tabhost same activity
I'm going to create an activity that shows statistic. I planned to have a TabHost with two tabs, the first one displays data in a table and the second tab displays a js diagram of the same data using a webview. So, since they share the same data and开发者_如何学C everything, I thought the easist way would be to create one activity/class and then play with the views. However, I would be delighted to get some good examples for how to do this. All I find is how it's done the opposite way, with separate activities.
Regards
This is an example XML file for TabHost:
<RelativeLayout android:id="@+id/tabhost1" style="?left_half_tabhost_holder">
<TabHost style="?tabhost"
<RelativeLayout style="?tabhost_countainer">
<FrameLayout style="?tab_content">
<ScrollView android:id="@+id/tab1" style="?tabtype_scrollview">
<ImageView style="?tab_content_mockup_map" android:onClick="onClickMap" />
</ScrollView>
<ScrollView android:id="@+id/tab2" style="?tabtype_scrollview">
<ImageView style="?tab_content_mockup_email" android:onClick="onClickMessages" />
</ScrollView>
<ScrollView android:id="@+id/tab3" style="?tabtype_scrollview">
<ImageView style="?tab_content_mockup_workload" android:onClick="onClickWorkload" />
</ScrollView>
</FrameLayout>
<TabWidget style="?tabwidget" />
</RelativeLayout>
</TabHost>
</RelativeLayout>
And the code to setup the tabs:
private void SetupMainTabHost()
{
View v = null;
v = findViewById(R.id.tabhost1);
mMainTabhost = (TabHost) v.findViewById(android.R.id.tabhost);
mMainTabhost.setup();
TabSpec spec = mMainTabhost.newTabSpec("tab1");
spec.setContent(R.id.tab1);
// getString(R.string.settings_tab_caption_1)
spec.setIndicator(getString(R.string.maptabtitle));
mMainTabhost.addTab(spec);
spec = mMainTabhost.newTabSpec("tab2");
spec.setContent(R.id.tab2);
spec.setIndicator(getString(R.string.messagetabtitle));
mMainTabhost.addTab(spec);
spec = mMainTabhost.newTabSpec("tab3");
spec.setContent(R.id.tab3);
spec.setIndicator(getString(R.string.workloadtabtitle));
mMainTabhost.addTab(spec);
}
Hope this helps.
精彩评论