2013-08-02 27 views
0

我想查看選擇了哪個選項卡並根據該選擇執行特定的代碼。我已經使用以下教程來創建包含圖像的列表,問題是列表項目位於單獨的選項卡中,我所關注的代碼僅設置第一個選項卡的圖像。如何檢查在Android中打開哪個選項卡tabview

http://www.debugrelease.com/2013/06/24/android-listview-tutorial-with-images-and-text/

下面是我設置的選項卡。

 TabHost tabHost = getTabHost(); 

     //Tab for Students 
     TabSpec studentSpec = tabHost.newTabSpec("Students"); 
     //set the tile and icon 
     studentSpec.setIndicator("Students", getResources().getDrawable(R.drawable.icon_students)); 
     Intent songsIntent = new Intent(this, StudentsTab.class); 
     studentSpec.setContent(songsIntent); 

     //Tab for Support 
     TabSpec supportSpec = tabHost.newTabSpec("Support"); 
     //set the tile and icon 
     supportSpec.setIndicator("Support", getResources().getDrawable(R.drawable.icon_support)); 
     Intent videosIntent = new Intent(this, SupportTab.class); 
     supportSpec.setContent(videosIntent); 

     //tabHost.addTab(homeSpec); 
     tabHost.addTab(studentSpec); 
     tabHost.addTab(supportSpec); 

    } 

所以我在本教程的Model.java類中有兩個方法,每個方法都運行相應的圖標和文本。我需要在特定的選項卡上調用這些選項。

謝謝!

+1

tabhost在Android中現已棄用。所以我會建議不要使用它。 –

回答

1

正如armaan陌生人指出的,標籤已過時,您應該使用操作欄標籤。有一個good sample on how to create swipe tabs on android.developer

如果你仍然想使用已棄用的(你不應該),那麼你需要實現OnTabChangeListener然後就可以看到這片被稱爲public void onTabChanged(String tabId)

0

您可以使用getCurrentTab()返回從0開始的索引開始索引。

相關問題