Android无法保留嵌套在其他片段的片段 [英] Android Can't retain fragments that are nested in other fragments
问题描述
有某事错了我的申请,我尽量的中添加三个片段另一个片段,然后在Eclipse表明这一点:
java.lang.IllegalStateException:不能保留嵌套在其他片段fragements
这是我的code在childFragments
getChildFragmentManager()的BeginTransaction()
。新增(R.id.shop_fragment_container,shopTopOneFragment)
。新增(R.id.shop_fragment_container,shopTopTwoFragment)
。新增(R.id.shop_fragment_container,shopTopThreeFragment)
.hide(shopTopTwoFragment).hide(shopTopThreeFragment)
.show(shopTopOneFragment).commit();
任何帮助将AP preciated
不能保留嵌套在其他片段fragements
这是嵌套的片段的限制
。我猜一个或多个孩子的片段
有 setRetainInstance(真)
的地方在其code。您需要删除,以prevent错误。
编辑:在进一步阅读,似乎如果父片段
呼吁 setRetainInstance(真)
那么就会造成由于这样的事实,试图保持母体实例也试图保留子相同的异常片段
there is sth wrong with my Application,I try to add three Fragments in another Fragment,then the Eclipse show this:
java.lang.IllegalStateException: Can't retain fragements that are nested in other fragments
this is my code in the childFragments
getChildFragmentManager().beginTransaction()
.add(R.id.shop_fragment_container, shopTopOneFragment)
.add(R.id.shop_fragment_container, shopTopTwoFragment)
.add(R.id.shop_fragment_container, shopTopThreeFragment)
.hide(shopTopTwoFragment).hide(shopTopThreeFragment)
.show(shopTopOneFragment).commit();
any help will be appreciated
Can't retain fragements that are nested in other fragments
This is a limitation of nested Fragments
. I'm guessing one or more of your child Fragments
have setRetainInstance(true)
somewhere in their code. You need to remove that to prevent the error.
EDIT: On further reading it seems if the parent Fragment
is calling setRetainInstance(true)
then it will cause the same exception due to the fact that attempting to retain the parent instance also attempts to retain the child Fragments
.
这篇关于Android无法保留嵌套在其他片段的片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!