这是我的onNavigationItemSelected方法:
}
答案 0 :(得分:1)
这样做:
int id = item.getItemId();
FragmentTransaction fragmentTransaction;
if (id == R.id.nav_sports) {
fragment = new FragmentOne();
} else if (id == R.id.nav_food) {
fragment = new FragmentTwo();
} else if (id == R.id.nav_security) {
fragment = new FragmentThree();
}
if (fragment != null) {
fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.containerView, fragment).commit();
}
答案 1 :(得分:0)
public void onDestroyView() {
super.onDestroyView();
FragmentManager fManager = getActivity().getSupportFragmentManager();
Fragment frag = fManager.findFragmentById(R.id.map);
if (frag != null)
fManager.beginTransaction().remove(frag).commit();
}
将其保留在片段中