1

I have this basic tab bar layout that creates a tab for three activities. What if I wanted to swap the activities within of the main activities?

I want it to work like the Contacts app where you have your main contacts tab and a detailed activity when you click on a contact.

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

    }*
Adam
  • 8,849
  • 16
  • 67
  • 131

1 Answers1

1

If you are asking how to start a brand new activity, which will replace your activity with the TabHost, then I believe you would start this new activity normally with

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

On the other hand, if you are asking about how to change the activity within a tab, then this thread looks like what you want.

Community
  • 1
  • 1
skynet
  • 9,898
  • 5
  • 43
  • 52