Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 27th, 2012  |  syntax: None  |  size: 1.44 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Switching between activities within a tab bar layout
  2. public void onCreate(Bundle savedInstanceState) {
  3.             super.onCreate(savedInstanceState);
  4.             setContentView(R.layout.main);
  5.  
  6.             TabHost tabHost = getTabHost();
  7.  
  8.             // Tab for Photos
  9.         TabSpec photospec = tabHost.newTabSpec("Photos");
  10.         // setting Title and Icon for the Tab
  11.         photospec.setIndicator("Photos", getResources().getDrawable(R.drawable.icon_photos_tab));
  12.         Intent photosIntent = new Intent(this, PhotosActivity.class);
  13.         photospec.setContent(photosIntent);
  14.  
  15.         // Tab for Songs
  16.         TabSpec songspec = tabHost.newTabSpec("Songs");
  17.         songspec.setIndicator("Songs", getResources().getDrawable(R.drawable.icon_songs_tab));
  18.         Intent songsIntent = new Intent(this, SongsActivity.class);
  19.         songspec.setContent(songsIntent);
  20.  
  21.         // Tab for Videos
  22.         TabSpec videospec = tabHost.newTabSpec("Videos");
  23.         videospec.setIndicator("Videos", getResources().getDrawable(R.drawable.icon_videos_tab));
  24.         Intent videosIntent = new Intent(this, VideosActivity.class);
  25.         videospec.setContent(videosIntent);
  26.  
  27.         // Adding all TabSpec to TabHost
  28.         tabHost.addTab(photospec); // Adding photos tab
  29.         tabHost.addTab(songspec); // Adding songs tab
  30.         tabHost.addTab(videospec); // Adding videos tab
  31.  
  32.     }*
  33.        
  34. Intent intent = new Intent(this, NewActivity.class);
  35. startActivity(intent);