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

Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 2.01 KB  |  hits: 13  |  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. How to change titles/contents for TabSpec in TabHost?
  2. TabHost.TabSpec spec=mTabHostCategories.newTabSpec("Main");    
  3. spec.setIndicator("Main");
  4. spec.setContent(R.id.listViewMain);
  5. mTabHostCategories.addTab(spec);
  6.  
  7. mTabSpecFirst=mTabHostCategories.newTabSpec("First");
  8. mTabSpecFirst.setContent(R.id.listViewFirst);
  9. mTabSpecFirst.setIndicator(mCategoryFirst);
  10. mTabHostCategories.addTab(mTabSpecFirst);
  11.  
  12. mTabSpecSecond=mTabHostCategories.newTabSpec("Second");
  13. mTabSpecSecond.setContent(R.id.listViewSecond);
  14. mTabSpecSecond.setIndicator(mCategorySecond);
  15. mTabHostCategories.addTab(mTabSpecSecond);    
  16.  
  17. mTabHostCategories.setCurrentTab(0);
  18.        
  19. Resources res = getResources(); // Resource object to get Drawables
  20.     TabHost tabHost = getTabHost(); // The activity TabHost
  21.     TabHost.TabSpec spec; // Resusable TabSpec for each tab
  22.     Intent intent; // Reusable Intent for each tab
  23.  
  24.     // Create an Intent to launch an Activity for the tab (to be reused)
  25.     intent = new Intent().setClass(this, TodaysTakeDemoActivity.class);
  26.     // Initialize a TabSpec for each tab and add it to the TabHost
  27.     spec = tabHost.newTabSpec("todaystake").setIndicator("Todays Take",
  28.             res.getDrawable(R.drawable.icontodaystake)).setContent(intent);
  29.     tabHost.addTab(spec);
  30.  
  31.     // Do the same for the other tabs
  32.     intent = new Intent().setClass(this, WhatsCasting.class);
  33.     spec = tabHost.newTabSpec("whatscasting").setIndicator(
  34.             "What's Casting", res.getDrawable(R.drawable.iconwhatscasting))
  35.             .setContent(intent);
  36.     tabHost.addTab(spec);
  37.  
  38.     intent = new Intent().setClass(this, Contacts.class);
  39.     spec = tabHost.newTabSpec("contacts").setIndicator("Contacts",
  40.             res.getDrawable(R.drawable.iconcontact)).setContent(intent);
  41.     tabHost.addTab(spec);
  42.  
  43.     intent = new Intent().setClass(this, TopListActivity.class);
  44.     spec = tabHost.newTabSpec("actortools").setIndicator("Actor Tools",
  45.             res.getDrawable(R.drawable.icontop10)).setContent(intent);
  46.     tabHost.addTab(spec);
  47.  
  48.     tabHost.setCurrentTab(0);