0

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

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 被贬低,也许有人知道解决方案。谢谢 :)

4

1 回答 1

0

扩展ActivityGroup代替Activity和代替mTabHost.setup()使用mTabHost.setup(getLocalActivityManager());

于 2012-04-16T06:27:10.810 回答