ViewPager:递归进入executePendingTransactions

时间:2011-09-07 18:36:35

标签: android android-3.0-honeycomb

我在ViewPager中有一个ViewPager,我得到了这个异常

09-07 18:30:26.392: ERROR/AndroidRuntime(841): FATAL EXCEPTION: main
    java.lang.IllegalStateException: Recursive entry to executePendingTransactions
    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1331)
    at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:422)
    at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:86)
    at android.support.v4.view.ViewPager.populate(ViewPager.java:453)
    at android.support.v4.view.ViewPager.onAttachedToWindow(ViewPager.java:563)
    at android.view.View.dispatchAttachedToWindow(View.java:7974)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1857)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1862)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1862)
    at android.view.ViewGroup.addViewInner(ViewGroup.java:2968)
    at android.view.ViewGroup.addView(ViewGroup.java:2824)
    at android.support.v4.view.ViewPager.addView(ViewPager.java:537)
    at android.view.ViewGroup.addView(ViewGroup.java:2781)
    at android.view.ViewGroup.addView(ViewGroup.java:2761)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:848)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1041)
    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:616)
    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1359)
    at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:422)
    at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:86)
    at android.support.v4.view.ViewPager.populate(ViewPager.java:453)
    at android.support.v4.view.ViewPager.onAttachedToWindow(ViewPager.java:563)
    at android.view.View.dispatchAttachedToWindow(View.java:7974)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1857)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1862)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1862)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1862)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1862)
    at android.view.ViewRoot.performTraversals(ViewRoot.java:726)
    at android.view.ViewRoot.handleMessage(ViewRoot.java:1944)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:126)
    at android.app.ActivityThread.main(ActivityThread.java:3997)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:491)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
    at dalvik.system.NativeStart.main(Native Method)

我不确定这个错误来自哪里,我不太了解FragmentManager。我是否需要刷新交易或类似的事情?或者ViewPager中的viewPager是不可能的?是的,我知道有其他方法可以做到这一点,但我想要快速和滚动免费。我也想了解它是如何运作的。

3 个答案:

答案 0 :(得分:101)

新版Support Library v4(或Android 4.2,of course)解决此问题非常简单。为此,只需执行自定义FragmentPagerAdapter的构造函数,如下所示:

public CustomFragmentPagerAdapter(android.support.v4.app.Fragment fragment)
{
    super(fragment.getChildFragmentManager());

    // write your code here
}

这项工作是因为新的Android版本批准使用嵌套片段

答案 1 :(得分:27)

最近我遇到了同样的问题,经过一番调查后,我惊讶地发现你根本无法将一个片段嵌入到另一个片段中。在这里,您将在另一个中执行一个片段事务。这是不允许的。

支持库v4的新版本(当然还是Android 4.2)解决了这个问题。请参阅下面的答案。

<强>更新 getChildFragmentManager ()已添加以解决上述问题。

答案 2 :(得分:7)

参考这个。 Display fragment viewpager within a fragment

可以这样做,但是必须通过Asysnc完成,因为你必须先让第一个片段事务完成。您可以在片段中包含片段。我知道,因为我有几个项目在做。