美文网首页
正确切换Fragment

正确切换Fragment

作者: shuixingge | 来源:发表于2016-08-21 20:16 被阅读65次
       private void switchFragment(Class<?> clazz) {
            Fragment to = ViewUtils.createFragment(clazz);
            if (to.isAdded()) {
                Log.i(TAG, "Added");
                mFragmentManager.beginTransaction().hide(mCurrentFragment).show(to).commitAllowingStateLoss();
            } else {
                Log.i(TAG, "Not Added");
                try {
                    mFragmentManager.beginTransaction().hide(mCurrentFragment).add(R.id.drawer_frame, to).commitAllowingStateLoss();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            mCurrentFragment = to;
        }
    

    相关文章

      网友评论

          本文标题:正确切换Fragment

          本文链接:https://www.haomeiwen.com/subject/dudwsttx.html