13

从今天早上开始的支持库的最后一个版本(Android Support Package v4 revision 11)应该支持嵌套片段。

在我的项目中,我有一个包含ViewPager的片段,而这个 ViewPager 包含几个片段。

我打电话getSupportFragmentManager()而不是getFragmentManager使用支持库的FragmentManager

问题是我仍然遇到崩溃,例如:

java.lang.IllegalStateException: Recursive entry to executePendingTransactions
    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416)
    at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461)
    at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
    at android.support.v4.view.ViewPager.populate(ViewPager.java:1012)
    at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:523)
    at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:495)
    at android.support.v4.view.ViewPager.onRestoreInstanceState(ViewPager.java:1221)
    at android.view.View.dispatchRestoreInstanceState(View.java:11910)
    at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2584)
    at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2590)
    at android.view.View.restoreHierarchyState(View.java:11888)
    at android.support.v4.app.Fragment.restoreViewState(Fragment.java:417)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:933)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
    at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:429)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4745)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)

有什么我做错了吗?或者支持不支持真正的嵌套片段?

我的交易就这么简单:

getSupportFragmentManager().beginTransaction()
                    .replace(R.id.content, new MyFragment()).commit();
4

1 回答 1

19

尝试使用getChildFragmentManager()而不是getSupportFragmentManager(). 这应该有帮助

于 2012-11-20T04:58:38.680 回答