2011-06-13 33 views
0

我對標籤佈局中的ListView佈局的實現有疑問。如何在TabView中實現ListView?

當我們實現這一點時,我們有一個自定義標題欄,其下是一個標籤佈局,在每個標籤佈局內有一個列表視圖,如果主要活動是ListView的擴展,或者它應該是標籤視圖的擴展?它可以是列表視圖?

原因是我創建了一個ListView正常運行,我想通過使用該列表作爲模板並添加分支到更多此類列表的Tabs(分類)來擴展它。我已經使用ListView來完成它,並且似乎要添加選項卡會要求我通過擴展tabview來重寫我的整個代碼。有沒有什麼辦法可以在執行我的標籤頁時使用ListView

我注意到沒有關於如何一起實現這兩個視圖/佈局的教程,任何人都有任何鏈接和方向?

+0

在這種情況下,您應該使用ActivityGroup而不是Activity,然後在單個選項卡中添加活動組,以便一次控制多個活動。 – DynamicMind 2011-06-13 11:41:32

+0

嗨動態的心態,謝謝!我認爲它是一個很好的探索點,如果你有任何好的教程來了解更多關於如何使用它的信息,那會好嗎?我知道我總是可以谷歌,但你有什麼好的ActivityGroup教程的個人建議? – jamen 2011-06-14 11:45:27

回答

3

我在前段時間寫的一些代碼中有這樣的例子。

我需要的也是一個選項卡內的列表。所以這個驅動程序是其中有其他活動的選項卡。將具有ListActivity Intent的TabSpec添加到TabHost。

這是選項卡的佈局:

<?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="fill_parent" 
    android:layout_height="fill_parent"> 
    <LinearLayout 
     android:orientation="vertical" 
     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" 
      /> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:padding="5dp" /> 
    </LinearLayout> 
</TabHost> 

那麼這就是在標籤列表視圖中的一個佈局:

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <ListView android:id="@+id/android:list" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"/> 
    <TextView android:id="@+id/android:empty" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:text="@string/no_items"/> 
</LinearLayout> 

這是對標籤本身的代碼:

公共類

MyTabActivity extends TabActivity { 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
      setContentView(R.layout.my_tabs); 
      Bundle bundle = getIntent().getExtras(); 

      TabHost tabHost = getTabHost(); 
      TabHost.TabSpec spec; 
      Intent intent; 

      intent = new Intent().setClass(this, MyListActivity.class); 
      spec = tabHost .newTabSpec("some_things") 
          .setIndicator("Some") 
          .setContent(intent); 
      tabHost.addTab(spec); 

      intent = new Intent().setClass(this, MyOtherActivity.class); 
      spec = tabHost .newTabSpec("top_things") 
          .setIndicator("Top") 
          .setContent(intent); 
      tabHost.addTab(spec); 


      tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 35; 
      tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 35; 
    } 
} 
+0

嗨拉謝爾,謝謝!那麼我會假設在每個tabs_activity內都有一個列表活動,它將每個標籤填充到它們各自的列表中? – jamen 2011-06-14 11:44:10

+0

是的,您將ListActivities添加到TabActivity java代碼中的TabHost,並且這些ListActivites控制它們顯示的列表。 TabActivity只是知道它應該在每個窗格中顯示的內容,ListActivities知道在列表中顯示的內容。 – Rachel 2011-06-14 11:47:31

相關問題