0

I have a custom FragmentWrapper class from which I want to return a new instance every time.

But inside it, I wan't to display another Singleton Fragment from each instance.

i.e. There should be a single fragment of SingletonFragment. And, all the instances of FragmentWrapper should display that Singleton fragment.

I tried using nested fragment through fragmentchildmanager but it is not working.

Below is the code:

@Override

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    final View root = inflater.inflate(R.layout.xxxlayout, container, false);

    getChildFragmentManager().beginTransaction()

            .replace(R.id.xxxcontainer, singletonfragment)

            .commit();

    return root;

}

Please suggest.

shruti1810
  • 3,920
  • 2
  • 16
  • 28

1 Answers1

0

after commit add following line

getChildFragmentManager().executePendingTransactions();

like this:

@Override

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    final View root = inflater.inflate(R.layout.xxxlayout, container, false);

    getChildFragmentManager().beginTransaction()

            .replace(R.id.xxxcontainer, singletonfragment)

            .commit();
    getChildFragmentManager().executePendingTransactions();
    return root;

}
Talon
  • 43
  • 1
  • 12