2011-10-25 20 views
1

私は、この3つのアクティビティのタブを作成するこの基本タブバーレイアウトを持っています。主な活動の中で活動を交換したいのですが?タブバーレイアウト内のアクティビティの切り替え

私はそれがあなたのメインの連絡先タブを持っている連絡先アプリのように動作し、連絡先をクリックすると詳細な動作がしたい。

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

関連する問題