How to disconnect a box in a fragment and go back to the correct fragment

I have a basic action with a fragment layout. The box has 3 options:

Fragment[1], Fragment[2], Fragment[3].

The inner fragment [2] and fragment [3] are one button. This button opens another fragment. Fragment [4].

I want Fragment [4] without a box, but with a back button.

This is the onClick code in the snippet [2]

 Fragment fragment = new InstalacionesEncontradasFragment(); Bundle bundle = new Bundle(); bundle.putSerializable("key", this.instalacionesConCategorias); fragment.setArguments(bundle); FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction mFragmentTransaction = fragmentManager.beginTransaction(); mFragmentTransaction.addToBackStack(null); mFragmentTransaction.replace(R.id.main_frame_container, fragment, "ACTIVIDADES").commit(); 

And in the Fragment [4]

onCreate a method:

 getActivity().getActionBar().setDisplayHomeAsUpEnabled(true); 

But this solution does not work.

How to disconnect a box? Where should I use the back button? In fragment [2] or fragment [3]?

+5
source share
1 answer
  • You can use:

     mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); 

    This will block the opening of the drawer on the swipe

  • Add line

     getActivity().getActionBar().setDisplayHomeAsUpEnabled(true); 

in the action, which makes all the fragments, such as fragments 1, 2,3 and 4. Maybe in your case, fragment 4 is different from the difference activity than fragment 2. Thus, pressing the "Back" button does not work.

+9
source

All Articles