您是否忘记致电公共无效设置(LocalActivityManager activityGroup)'?

时间:2014-04-25 10:15:44

标签: android tabs fragment

我正在使用片段标签编写一个简单的标签视图(因为TabActivity已被弃用)

但是当我尝试运行它时,它会发出错误警告"您是否忘记调用公共无效设置(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);
    }
}

1 个答案:

答案 0 :(得分:1)

尝试将FragmentTabHost类与addTab一起使用(TabSpec,FragmentClass,Bundle)

@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