Reputation: 17
This is my onNavigationItemSelected method:
}
Upvotes: 0
Views: 109
Reputation: 1575
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
Upvotes: 0
Reputation: 609
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();
}
Upvotes: 1