Skip to main content
adicionou 84 caracteres ao conteúdo
Fonte Link

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. Pode ver mais aqui.

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.

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. Pode ver mais aqui.

Fonte Link

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.