2011-02-10 69 views
2

我要創建一個顯示統計的活動。我計劃使用兩個選項卡的TabHost,第一個在一個表中顯示數據,第二個選項卡使用webview顯示相同數據的js圖。因此,由於他們共享相同的數據和所有內容,我認爲最簡單的方法就是創建一個活動/課程,然後使用這些視圖。但是,我很樂意爲您提供一些關於如何做到這一點的好例子。我發現的是,它是如何以相反的方式完成的,具有單獨的活動。android tabhost同樣的活動

問候

回答

0

這是TabHost一個示例XML文件:

<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> 

和代碼來設置標籤:

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); 
} 

希望這有助於。