Skip to main content
1 de 2

Para fazer a transição entre os fragments na MainActivity com o NavDrawer, eu uso assim:

   public void displayView(int viewId) {

        Fragment fragment = null;

        switch (viewId) {
            case R.id.fragment_1:
                fragment = new Fragment1();
                title  = "Fragment 1";
                break;
            case R.id.fragment_2:
                fragment = new Fragment2();
                title  = "Fragment 2";
                break;
        
        if (fragment != null) {
            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            ft.replace(R.id.content_frame, fragment);
            ft.commit();
        }

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);

    }

Espero ter ajudado.