我正在开发一个底部有一个标签的应用程序,每个标签点击都会替换当前片段,我试图替换片段,但我的应用程序崩溃没有任何错误,有人可以帮我解决吗?我的代码替换片段如下,
public class Tab5Container extends BaseContainerFragment {
private boolean IsViewInited;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.container_framelayout, null);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (!IsViewInited) {
IsViewInited = true;
initView();
}
}
private void initView() {
replaceFragment(new NewProfileFragment(), false);
}
}
basefragment
public class BaseContainerFragment extends Fragment {
public void replaceFragment(Fragment fragment, boolean addToBackStack) {
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
if (addToBackStack) {
transaction.addToBackStack(null);
}
transaction.replace(R.id.container_framelayout, fragment);
transaction.commit();
getChildFragmentManager().executePendingTransactions();
}
public boolean popFragment() {
Log.e("Ritesh", "pop fragment: " + getChildFragmentManager().getBackStackEntryCount());
boolean isPop = false;
if (getChildFragmentManager().getBackStackEntryCount() > 0) {
isPop = true;
getChildFragmentManager().popBackStack();
}
return isPop;
}
}
请帮助我,我为此浪费了1天.. :(