2011-10-25 41 views
1

我有這個基本標籤欄佈局,可以爲三個活動創建標籤。如果我想交換主要活動中的活動,該怎麼辦?在標籤欄佈局內切換活動

我希望它能夠像聯繫人應用那樣工作,在那裏您有主要聯繫人標籤,並在點擊聯繫人時提供詳細的活動。

public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.main); 

      TabHost tabHost = getTabHost(); 

      // Tab for Photos 
     TabSpec photospec = tabHost.newTabSpec("Photos"); 
     // setting Title and Icon for the Tab 
     photospec.setIndicator("Photos", getResources().getDrawable(R.drawable.icon_photos_tab)); 
     Intent photosIntent = new Intent(this, PhotosActivity.class); 
     photospec.setContent(photosIntent); 

     // Tab for Songs 
     TabSpec songspec = tabHost.newTabSpec("Songs"); 
     songspec.setIndicator("Songs", getResources().getDrawable(R.drawable.icon_songs_tab)); 
     Intent songsIntent = new Intent(this, SongsActivity.class); 
     songspec.setContent(songsIntent); 

     // Tab for Videos 
     TabSpec videospec = tabHost.newTabSpec("Videos"); 
     videospec.setIndicator("Videos", getResources().getDrawable(R.drawable.icon_videos_tab)); 
     Intent videosIntent = new Intent(this, VideosActivity.class); 
     videospec.setContent(videosIntent); 

     // Adding all TabSpec to TabHost 
     tabHost.addTab(photospec); // Adding photos tab 
     tabHost.addTab(songspec); // Adding songs tab 
     tabHost.addTab(videospec); // Adding videos tab 

    }* 
+0

所以你想要像標籤內的一個標籤,當你點擊標籤項目? –

回答

1

如果你問如何啓動一個全新的活動,將與TabHost取代你的活動,那麼我相信你會與

Intent intent = new Intent(this, NewActivity.class); 
startActivity(intent); 

正常啓動這一新的活動在另一方面,如果您詢問如何更改標籤內的活動,那麼this thread看起來像你想要的。

+0

我不完全確定如何在鏈接中實現示例。它不完整? – Adam