Stanley Tutu Dinala
Stanley Tutu Dinala

Reputation: 17

My app crashes when I press navigation item twice using map View

This is my onNavigationItemSelected method:

        }

Upvotes: 0

Views: 109

Answers (2)

Srikanth
Srikanth

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

Salman Shaikh
Salman Shaikh

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

Related Questions