2012-01-26 85 views
0

我一直在開發應用程序,用來製作TabHost下面的代碼:如何在TabHost中更改TabSpec的標題/內容?

TabHost.TabSpec spec=mTabHostCategories.newTabSpec("Main");  
spec.setIndicator("Main"); 
spec.setContent(R.id.listViewMain); 
mTabHostCategories.addTab(spec); 

mTabSpecFirst=mTabHostCategories.newTabSpec("First"); 
mTabSpecFirst.setContent(R.id.listViewFirst); 
mTabSpecFirst.setIndicator(mCategoryFirst); 
mTabHostCategories.addTab(mTabSpecFirst); 

mTabSpecSecond=mTabHostCategories.newTabSpec("Second"); 
mTabSpecSecond.setContent(R.id.listViewSecond); 
mTabSpecSecond.setIndicator(mCategorySecond); 
mTabHostCategories.addTab(mTabSpecSecond);  

mTabHostCategories.setCurrentTab(0); 

但後來我需要改變標題(指標)和內容TabSpecs。我該怎麼做?謝謝。

回答

0

你需要與你所要的標題更改標題您mCategoryFirst 或簡單的通過一個新的TextView你則tabspec對象

+0

mCategoryFirst是簡單的String對象。我該如何改變它? – user1166635

+0

然後只需調用'mTabSpecFirst.SetIndicator(「new title」);'更改第一個標籤的標題 – waqaslam

0
Resources res = getResources(); // Resource object to get Drawables 
    TabHost tabHost = getTabHost(); // The activity TabHost 
    TabHost.TabSpec spec; // Resusable TabSpec for each tab 
    Intent intent; // Reusable Intent for each tab 

    // Create an Intent to launch an Activity for the tab (to be reused) 
    intent = new Intent().setClass(this, TodaysTakeDemoActivity.class); 
    // Initialize a TabSpec for each tab and add it to the TabHost 
    spec = tabHost.newTabSpec("todaystake").setIndicator("Todays Take", 
      res.getDrawable(R.drawable.icontodaystake)).setContent(intent); 
    tabHost.addTab(spec); 

    // Do the same for the other tabs 
    intent = new Intent().setClass(this, WhatsCasting.class); 
    spec = tabHost.newTabSpec("whatscasting").setIndicator(
      "What's Casting", res.getDrawable(R.drawable.iconwhatscasting)) 
      .setContent(intent); 
    tabHost.addTab(spec); 

    intent = new Intent().setClass(this, Contacts.class); 
    spec = tabHost.newTabSpec("contacts").setIndicator("Contacts", 
      res.getDrawable(R.drawable.iconcontact)).setContent(intent); 
    tabHost.addTab(spec); 

    intent = new Intent().setClass(this, TopListActivity.class); 
    spec = tabHost.newTabSpec("actortools").setIndicator("Actor Tools", 
      res.getDrawable(R.drawable.icontop10)).setContent(intent); 
    tabHost.addTab(spec); 

    tabHost.setCurrentTab(0);