//判断此Fragment是否已经添加到FragmentTransaction事物中
if (!fragment.isAdded()) {
transaction.add(R.id.fragment_container, fragment, tag);
} else {
transaction.show(fragment);
}
我明明做了判断为什么还是会报错?
解决方案
getSupportFragmentManager().executePendingTransactions();
//判断此Fragment是否已经添加到FragmentTransaction事物中
if (!fragment.isAdded()) {
transaction.add(R.id.fragment_container, fragment, tag);
} else {
transaction.show(fragment);
}