Fragment Android

0

I'm trying to make an app with the Navigation Drawer layout, but it uses Fragments, I can not call another screen using Fragments.

             Login fragment = new Login();
             android.support.v4.app.FragmentTransaction fragmentTransaction =                              getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.fragment_container, fragment);
        fragmentTransaction.commit();

A code that I used, but no more, of the error in the fragment_container. Could someone help?

    
asked by anonymous 05.01.2017 / 19:04

1 answer

0

Look like this:

        Login fragment = new Login();
        FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.fragment_container, fragment);
        transaction.addToBackStack(null);
        transaction.commit();

Here I am using getActivity() because I am calling the login fragment from within another fragment. You may have to adapt to your logic.

    
05.01.2017 / 19:10