0

我的操作栏有问题,我解释得很好。因此,如果我在一个选项卡上(选择说),如果 cliccassi 不小心使应用程序崩溃,我希望不会发生......但我无法理解。我将发布一些我在 TAB 配置的主要活动中放入的代码。

private class TabListener<T extends Fragment> implements ActionBar.TabListener {

    private Fragment mFragment;

    private final Activity mActivity;

    private final String mTag;

    private final Class<T> mClass;

    public TabListener(Activity activity, String tag, Class<T> clz) {

        mActivity = activity;

        mTag = tag;

        mClass = clz;

    }
    public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {

        // Check if the fragment is already initialized

        if (mFragment == null) {

            // If not, instantiate and add it to the activity

            mFragment = Fragment.instantiate(mActivity, mClass.getName());

            ft.add(android.R.id.content, mFragment, mTag);


        } else {

            // If it exists, simply attach it in order to show it
            ft.show(mFragment);
            //ft.attach(mFragment);

        }

    }
    public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {

        if (mFragment != null) {

            // Detach the fragment, because another one is being attached

           // ft.detach(mFragment);
            ft.hide(mFragment);
        }

    }
    public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {

            ft.replace(tab.getPosition(),mFragment);

        // User selected the already selected tab. Usually do nothing.
    }

}

日志:

    java.lang.IllegalArgumentException: Must use non-zero containerViewId
at android.app.BackStackRecord.replace(BackStackRecord.java:384)
at android.app.BackStackRecord.replace(BackStackRecord.java:379)
at com.megadonate.megadownloader.MainActivity$TabListener.onTabReselected(MainActivity.java:158)
at com.android.internal.app.ActionBarImpl.selectTab(ActionBarImpl.java:577)
at com.android.internal.app.ActionBarImpl$TabImpl.select(ActionBarImpl.java:1084)
at com.android.internal.widget.ScrollingTabContainerView$TabClickListener.onClick(ScrollingTabContainerView.java:537)
at android.view.View.performClick(View.java:4232)
at android.view.View$PerformClick.run(View.java:17318)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
4

1 回答 1

0

您似乎没有FragmentTransaction.
查看帖子以获取指南。

于 2013-08-24T09:02:45.307 回答