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

Untitled

By: a guest on May 26th, 2012  |  syntax: None  |  size: 1.78 KB  |  hits: 14  |  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. creating tabs using android app
  2. import android.app.TabActivity; //  - This is crossed in the middle
  3. import android.content.Intent;
  4. import android.content.res.Resources;
  5. import android.os.Bundle;
  6. import android.widget.TabHost;
  7.  
  8.  
  9. @SuppressWarnings("deprecation")
  10. public class DemonstratorActivity extends TabActivity {
  11.  
  12.      public void onCreate(Bundle savedInstanceState) {
  13.             super.onCreate(savedInstanceState);
  14.             setContentView(R.layout.main);
  15.  
  16.             Resources res = getResources();
  17.             TabHost tabHost = getTabHost();  // The activity TabHost - This is crossed in the middle
  18.             TabHost.TabSpec spec;
  19.             Intent intent;  
  20.  
  21.             // Create an Intent to launch an Activity for the tab (to be reused)
  22.             intent = new Intent().setClass(this, DriveActivity.class);
  23.  
  24.             // Initialize a TabSpec for each tab and add it to the TabHost
  25.             spec = tabHost.newTabSpec("Tab1").setIndicator("Tab1",
  26.                               res.getDrawable(R.drawable.Tab1picture))
  27.                           .setContent(intent);
  28.             tabHost.addTab(spec);
  29.  
  30.             // Do the same for the other tabs
  31.             intent = new Intent().setClass(this, LightsControlActivity.class);
  32.             spec = tabHost.newTabSpec("Tab2").setIndicator("Tab2",
  33.                               res.getDrawable(R.drawable.Tab2picture))
  34.                           .setContent(intent);
  35.             tabHost.addTab(spec);
  36.  
  37.             intent = new Intent().setClass(this, NavigationActivity.class);
  38.             spec = tabHost.newTabSpec("Tab3").setIndicator("Tab3",
  39.                               res.getDrawable(R.drawable.Tab3picture))
  40.                           .setContent(intent);
  41.             tabHost.addTab(spec);
  42.  
  43.             tabHost.setCurrentTab(2);
  44.         }
  45.     }