2011-12-30 10 views
1

1つのアクティビティタブホストを作成し、タブとビューを作成し、ビューをウィジェットで動的に移入するのが理想的です。画面の下部に「コントロール」ボタンがあることが重要です。複数のタブホストビューを使用して動的に移入する方法

3つのレイアウトを使用して3つのタブを作成できます。 a)へのEditTextsの表示、b)[Separatorを使った]タブの下に並んでいることは、StackOverflowの既存の回答によって助けられた課題でした。第2のレイアウト/タブのEditTextsが表示されない理由を最初のタブ上のものが行うのに対し、私は今出て働くことができない何

は、ありますか? 2番目のタブには3つのEditTextsは表示されません

レイアウト

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:padding="5dp" > 
     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"/> 
      <View 
       android:id="@+id/separator" 
       android:layout_below="@android:id/tabs" 
       android:layout_width="fill_parent" 
       android:layout_height="2dip" /> 
      <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_below="@+id/separator" 
      android:layout_above="@+id/btnSend" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 
      <LinearLayout 
       android:id="@+id/tabview1" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="vertical"> 
       <TextView 
       android:id="@+id/ll1text" 
       android:layout_height="wrap_content" 
       android:layout_width="fill_parent" 
       android:text="ll1text" /> 
      </LinearLayout> 
      <LinearLayout 
       android:id="@+id/tabview2" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="vertical"> 
      <TextView 
       android:id="@+id/ll2text" 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent" 
       android:text="ll2text" /> 
      </LinearLayout> 
      <RelativeLayout 
       android:id="@+id/tabview3" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="vertical" > 
      <TextView 
       android:id="@+id/rl3text" 
       android:layout_height="wrap_content" 
       android:layout_width="fill_parent" 
       android:layout_alignParentBottom="true" 
       android:text="ll3text" /> 
      </RelativeLayout> 
      </FrameLayout> 
     <Button 
      android:layout_alignParentBottom="true" 
      android:text="Start Travelling" 
      android:id="@+id/btnSend" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:layout_width="fill_parent" /> 
    </RelativeLayout> 
</TabHost> 

アクティビティコード

setContentView(R.layout.template); 
    TabHost th = getTabHost(); 

th.addTab(th.newTabSpec("tab1").setIndicator("Customer").setContent(R.id.tabview1)); 
    LinearLayout ll = (LinearLayout) findViewById(R.id.tabview1); 
    EditText et1 = new EditText (this); 
    et1.setText("ET1"); 
    ll.addView(et1); 
    TextView tv2 = new TextView(this); 
    tv2.setText("et2:"); 
    ll.addView(tv2); 
    EditText et2 = new EditText (this); 
    et2.setText("ET2"); 
    ll.addView(et2); 

    th.addTab(th.newTabSpec("tab2").setIndicator("Job").setContent(R.id.tabview2)); 
    ll = (LinearLayout) findViewById(R.id.tabview2); 
    EditText et21 = new EditText (this); 
    et21.setText("et21"); 
    ll.addView(et21); 
    EditText et22 = new EditText (this); 
    et22.setText("et22"); 
    ll.addView(et22); 
    EditText et23 = new EditText (this); 
    et23.setText("et23"); 
    ll.addView(et23); 

    th.addTab(th.newTabSpec("tab3").setIndicator("Tab 3").setContent(R.id.tabview3)); 
    RelativeLayout rl = (RelativeLayout) findViewById(R.id.tabview3); 
    EditText et3 = new EditText (this); 
    et3.setText("ET3"); 
    rl.addView(et3); 

    th.setCurrentTab(0); 

どのように来ますか?

答えて

0

私はこの問題は、あなたが1つのアクティビティの下にすべてのタブを保持しようとしているということだと思います。次のようにして、それらを分離する必要があります

  • あなたのタブごとに異なるアクティビティを作成

    • TabActivity
    • を扱うクラスを使用しtabhostレイアウト

    を追加助けをthis tutorialをチェック。

  • 関連する問題