getChildFragment()要在什么情况下使用?

新手上路,请多包涵

是谁的方法?

阅读 10.9k
1 个回答
✓ 已被采纳新手上路,请多包涵

自问自答~,作为范例
这个方法是Fragment的方法,用来在Fragment上管理Fragment;
使用时,如果用的V4包,会碰到no Activity错误,是因为v4包没重置childFragmentManager,重写父Fragment的onDetch方法,来解决:

   public void onDetach() {
               super.onDetach();
               try {
                    Field childFragmentManager = Fragment.class.getDeclaredField("mChildFragmentManager");
                    childFragmentManager.setAccessible(true);
                    childFragmentManager.set(this, null);
               } catch (NoSuchFieldException e) {
                    throw new RuntimeException(e);
               } catch (IllegalAccessException e) {
                    throw new RuntimeException(e);
               }
          }`

参考资料:
http://www.tuicool.com/articles/2eM32a
http://stackoverflow.com/questions/15207305/getting-the-error-java-lang-illegalstateexception-activity-has-been-destroyed

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题