2014-04-25 21 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

相关问题