-1

I gonna add one fragment to another fragment in frameLayout but I do not want to replace. I gonna when click on button second fragment show up and when click on back key second fragment hide now . I do not want first fragment destroyed . what should I do?

similar code:

transaction=getSupportFragmentManager().beginTransaction();
transaction.add(R.id.frame_fragment_containers,new FragmentCate() , "fragcate");
transaction.addToBackStack(null);
transaction.commit();
hamid keyhani
  • 451
  • 3
  • 12

1 Answers1

0

If you want to add fragment to another fragment, you can use getChildFragmentManager(). onActivityCreated of parent fragment, you can add another fragment just like below.



    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        getChildFragmentManager().beginTransaction()
                .add(R.id.My_Container_1_ID, "your fragment here")
                .commit();
    }

Narasing
  • 1
  • 7