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

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

是谁的方法?


自问自答~,作为范例
这个方法是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

【热门文章】
【热门文章】