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;
}
网友评论