我查看了有关类似问题的堆栈溢出的所有问题,但没有设法找到解决方案,这适合我的情况。
我需要实现以下结构: 片段A正在被片段B替换。片段B包含ViewPager,它切换片段C1和C2。如果我从支持库使用ViewPager,这很有效,但问题是,我需要一个ViewPager来使用垂直滑动。为此,我正在使用Jake Wharton的图书馆https://stackoverflow.com/a/14268702/1220743。
一些代码:
A正在被B
取代Fragment fragment = new FragmentB();
String tag = this.getClass().getName();
FragmentManager fm = getFragmentManager();
fm.beginTransaction().replace(R.id.container, fragment).addToBackStack(tag).commit();
B初始化DirectionalViewPager
DirectionalViewPager viewPager = (DirectionalViewPager)v.findViewById(R.id.view_pager);
FragmentManager fm = getFragmentManager();
viewPager.setAdapter(new MyViewPagerAdapter(fm));
当A切换到B时,这会让我崩溃,后面是崩溃堆栈:
08-18 16:47:02.320: E/AndroidRuntime(29610): FATAL EXCEPTION: main
08-18 16:47:02.320: E/AndroidRuntime(29610): java.lang.IllegalStateException: Recursive entry to executePendingTransactions
08-18 16:47:02.320: E/AndroidRuntime(29610): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1450)
08-18 16:47:02.320: E/AndroidRuntime(29610): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:478)
08-18 16:47:02.320: E/AndroidRuntime(29610): at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
08-18 16:47:02.320: E/AndroidRuntime(29610): at android.support.v4.view.DirectionalViewPager.populate(DirectionalViewPager.java:399)
08-18 16:47:02.320: E/AndroidRuntime(29610): at android.support.v4.view.DirectionalViewPager.onAttachedToWindow(DirectionalViewPager.java:550)
08-18 16:47:02.320: E/AndroidRuntime(29610): at android.view.View.dispatchAttachedToWindow(View.java:13029)
08-18 16:47:02.320: E/AndroidRuntime(29610): at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2683)
08-18 16:47:02.320: E/AndroidRuntime(29610): at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2690)
08-18 16:47:02.320: E/AndroidRuntime(29610): at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2690)
08-18 16:47:02.320: E/AndroidRuntime(29610): at android.view.ViewGroup.addViewInner(ViewGroup.java:3778)
08-18 16:47:02.320: E/AndroidRuntime(29610): at android.view.ViewGroup.addView(ViewGroup.java:3610)
08-18 16:47:02.320: E/AndroidRuntime(29610): at android.view.ViewGroup.addView(ViewGroup.java:3555)
08-18 16:47:02.320: E/AndroidRuntime(29610): at android.view.ViewGroup.addView(ViewGroup.java:3531)
08-18 16:47:02.320: E/AndroidRuntime(29610): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:949)
08-18 16:47:02.320: E/AndroidRuntime(29610): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
08-18 16:47:02.320: E/AndroidRuntime(29610): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
08-18 16:47:02.320: E/AndroidRuntime(29610): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478)
08-18 16:47:02.320: E/AndroidRuntime(29610): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:446)
08-18 16:47:02.320: E/AndroidRuntime(29610): at android.os.Handler.handleCallback(Handler.java:730)
08-18 16:47:02.320: E/AndroidRuntime(29610): at android.os.Handler.dispatchMessage(Handler.java:92)
08-18 16:47:02.320: E/AndroidRuntime(29610): at android.os.Looper.loop(Looper.java:176)
08-18 16:47:02.320: E/AndroidRuntime(29610): at android.app.ActivityThread.main(ActivityThread.java:5419)
08-18 16:47:02.320: E/AndroidRuntime(29610): at java.lang.reflect.Method.invokeNative(Native Method)
08-18 16:47:02.320: E/AndroidRuntime(29610): at java.lang.reflect.Method.invoke(Method.java:525)
08-18 16:47:02.320: E/AndroidRuntime(29610): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
08-18 16:47:02.320: E/AndroidRuntime(29610): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
08-18 16:47:02.320: E/AndroidRuntime(29610): at dalvik.system.NativeStart.main(Native Method)
有没有人遇到过类似的问题?
答案 0 :(得分:0)
您有没有找到解决方案?已经在片段中的两个片段?若是这样使用getChildFragmentManager()对我来说好奇的是,getFragmentManager看起来好像你没有使用支持v4,或者它是getSupportFragmentManager没有?但是通过日志,当您使用支持库时,似乎发生了错误。