2011-02-10 17 views
2

統計を表示するアクティビティを作成します。私は2つのタブを持つTabHostを用意する予定でした。最初のタブはテーブルにデータを表示し、2番目のタブはwebviewを使って同じデータのjsダイアグラムを表示します。 それで、彼らは同じデータとすべてを共有しているので、私は簡単な方法は1つのアクティビティ/クラスを作成し、次にそのビューで再生することだと思いました。しかし、私はこれを行う方法の良い例を得ることができて嬉しく思います。私が見つけたのは、それが逆のやり方で、別々の活動でどのように行われたかです。アンドロイドタブホスト同じアクティビティ

よろしく

答えて

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

は、この情報がお役に立てば幸いです。

関連する問題