2014-04-25 30 views
0

我寫使用片段標籤(因爲TabActivity已被淘汰)你忘記調用'public void setup(LocalActivityManager activityGroup)'嗎?

一個簡單的標籤視圖但是當我嘗試運行它,它會提醒錯誤「難道你忘了叫‘公共無效設置(LocalActivityManager的ActivityGroup)’? 」。另外我注意到ActivityGroup和setup(void)也被棄用。

如何解決?

public class ListTab extends FragmentActivity{ 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 
     setContentView(R.layout.list_tab); 

     FragmentTabHost listTab = (FragmentTabHost)findViewById(R.id.list_tab_host); 

     listTab.setup(this, this.getSupportFragmentManager(), R.id.realtabcontent); 

     TabSpec allPostSpec = listTab.newTabSpec("all_post"); 
     allPostSpec.setIndicator("All"); 
     Intent allPostIntent = new Intent(this,ListPost.class); 
     allPostSpec.setContent(allPostIntent); 

     listTab.addTab(allPostSpec); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 

     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.list_post, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 
     if (id == R.id.action_settings) { 
      return true; 
     } 
     return super.onOptionsItemSelected(item); 
    } 
} 
+0

如果您正在使用FragmentTabHost不故意使用則tabspec ......用這個'addTab(TabHost.TabSpec則tabspec,類 CLSS,捆綁參數) 'addTab版本(記住clss應該是擴展Fragment的類) – Selvin

+0

我將它更改爲: listTab.addTab(listTab.newTabSpec(「all_post」).setIndicator(「All」),ListPost.class,null); 其中ListPost是擴展ListFragment 但錯誤還是一樣:( – Simon

回答

1

嘗試使用FragmentTabHost類addTab(則tabspec,FragmentClass,捆綁)

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.fragment_tabs); 
    mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost); 
    mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent); 
    mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"), 
    FragmentStackSupport.CountingFragment.class, null); 
    mTabHost.addTab(mTabHost.newTabSpec("contacts").setIndicator("Contacts"), 
        LoaderCursorSupport.CursorLoaderListFragment.class, null); 
    mTabHost.addTab(mTabHost.newTabSpec("custom").setIndicator("Custom"), 
        LoaderCustomSupport.AppListFragment.class, null); 
    mTabHost.addTab(mTabHost.newTabSpec("throttle").setIndicator("Throttle"), 
        LoaderThrottleSupport.ThrottledLoaderListFragment.class, null); 
} 

哪裏R.id.realtabcontent是你的容器。

你可以在這裏找到一個例子:

http://developer.android.com/reference/android/support/v4/app/FragmentTabHost.html

+1

,請複製粘貼在答題鏈接的相關部分。如果鏈接的變化,以後的人可能無法找到它。 – Machavity

+0

OK OK,固定,對不起,第一篇文章。 – WalterCool

相關問題