Dynamically add fragment into fragment

前端 未结 4 1749
花落未央
花落未央 2020-12-05 03:07

I haven\'t been able to find a way how to dynamically add fragment into existing dynamically added fragment. Do you know, if it is possible?

I am generating fragment

4条回答
  •  醉酒成梦
    2020-12-05 03:56

    As the documentation states "A fragment must always be embedded in an activity". So when you add a "sub-fragment" it will always belong to the activity even if you add it within your fragment class. For example if you later decide to remove the containing fragment the sub fragments won't be automatically removed. When I had to do the same I had to store in a vector the sub fragments and manually remove them in the onDestroy methods of my container fragment.

    I think that fragments are not thought to be used like this

提交回复
热议问题