使用支持库v4修订版11的嵌套片段

时间:2012-11-14 10:36:04

标签: android android-fragments android-viewpager android-support-library android-nested-fragment

今天早上支持库的最后一个版本(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();

1 个答案:

答案 0 :(得分:19)

尝试使用getChildFragmentManager()代替getSupportFragmentManager()。这应该有帮助