这是我的onNavigationItemSelected方法:
}
Do it like this:
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();
}
public void onDestroyView() {
super.onDestroyView();
FragmentManager fManager = getActivity().getSupportFragmentManager();
Fragment frag = fManager.findFragmentById(R.id.map);
if (frag != null)
fManager.beginTransaction().remove(frag).commit();
}
Keep this in your Fragment
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.