标签和碎片例外

时间:2012-04-16 06:22:50

标签: java android android-fragments actionbarsherlock

我想实现我的每个标签都有一个单独的活动的想法。这是我创建标签的代码:

public class MainTabActivity extends SherlockFragmentActivity {

    protected void onCreate(Bundle savedInstanceState) {

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

        try {
            TabHost mTabHost = (TabHost) findViewById(android.R.id.tabhost);

            mTabHost.setup();

            Resources res = getResources();

            TabHost.TabSpec spec;
            Intent intent;

            intent = new Intent().setClass(this, stackA.class);

            spec = mTabHost
                    .newTabSpec("tab1")
                    .setIndicator("Tab 1",
                            res.getDrawable(R.drawable.ic_launcher))
                    .setContent(intent);
            mTabHost.addTab(spec);

            intent = new Intent().setClass(this, stackB.class);

            spec = mTabHost
                    .newTabSpec("tab2")
                    .setIndicator("Tab 2",
                            res.getDrawable(R.drawable.ic_launcher))
                    .setContent(intent);
            mTabHost.addTab(spec);
            mTabHost.setCurrentTab(0);
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }



    }




}

我得到一个例外:

java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?

所以也许有人知道解决方案,如果我想扩展FragmentsActivity,因为TabActivity被删除。谢谢:))

1 个答案:

答案 0 :(得分:0)

扩展ActivityGroup而不是Activity而不是mTabHost.setup()使用mTabHost.setup(getLocalActivityManager());