Fragment Android

Asked

Viewed 65 times

0

I’m trying to make an app with the layout Navigation Drawer, but use Fragments, I’m not able to 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();

Code that I used, but not more, the fragment_container error. Someone could help?

1 answer

0

Look at it this way:

        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. Maybe you have to adapt to your logic.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.