Android无法保留嵌套在其他片段的片段 [英] Android Can't retain fragments that are nested in other fragments

查看:133
本文介绍了Android无法保留嵌套在其他片段的片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有某事错了我的申请,我尽量的中添加三个片段另一个片段,然后在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆