ager里面片段FragmentPagerAdapter开始交易

ager里面片段FragmentPagerAdapter开始交易

本文介绍了ViewPager里面片段FragmentPagerAdapter开始交易时,应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有一个ViewPager带片段内FragmentPagerAdapter,这是我一个的FrameLayout内显示。
一切工作正常,到目前为止,我可以在完全没有问题的片段之间交换我的FrameLayout里。

I have a ViewPager with a FragmentPagerAdapter inside a Fragment, which I display inside a FrameLayout.Everything works fine so far, I can swap between Fragments inside my FrameLayout with no problems at all.

但如果我轻弹ViewPager,然后快速交换到不同的片段中旬动画,我这个错误,应用程序崩溃:

BUT if I flick the ViewPager and then fast swap to a different Fragment mid animation, I this Error and the App crashes:

12-20 03:00:14.539: E/AndroidRuntime(20193): FATAL EXCEPTION: main
12-20 03:00:14.539: E/AndroidRuntime(20193): java.lang.IllegalArgumentException: No view found for id 0x7f0a002f for fragment NewsPagerFragment{4184f340 #4 id=0x7f0a002f android:switcher:2131361839:3}
12-20 03:00:14.539: E/AndroidRuntime(20193):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:822)
12-20 03:00:14.539: E/AndroidRuntime(20193):    at android.app.FragmentManagerImpl.attachFragment(FragmentManager.java:1206)
12-20 03:00:14.539: E/AndroidRuntime(20193):    at android.app.BackStackRecord.run(BackStackRecord.java:612)
12-20 03:00:14.539: E/AndroidRuntime(20193):    at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1382)
12-20 03:00:14.539: E/AndroidRuntime(20193):    at android.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:437)
12-20 03:00:14.539: E/AndroidRuntime(20193):    at android.support.v13.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:145)
12-20 03:00:14.539: E/AndroidRuntime(20193):    at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
12-20 03:00:14.539: E/AndroidRuntime(20193):    at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
12-20 03:00:14.539: E/AndroidRuntime(20193):    at android.support.v4.view.ViewPager$3.run(ViewPager.java:244)
12-20 03:00:14.539: E/AndroidRuntime(20193):    at android.os.Handler.handleCallback(Handler.java:605)
12-20 03:00:14.539: E/AndroidRuntime(20193):    at android.os.Handler.dispatchMessage(Handler.java:92)
12-20 03:00:14.539: E/AndroidRuntime(20193):    at android.os.Looper.loop(Looper.java:137)
12-20 03:00:14.539: E/AndroidRuntime(20193):    at android.app.ActivityThread.main(ActivityThread.java:4514)
12-20 03:00:14.539: E/AndroidRuntime(20193):    at java.lang.reflect.Method.invokeNative(Native Method)
12-20 03:00:14.539: E/AndroidRuntime(20193):    at java.lang.reflect.Method.invoke(Method.java:511)
12-20 03:00:14.539: E/AndroidRuntime(20193):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
12-20 03:00:14.539: E/AndroidRuntime(20193):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
12-20 03:00:14.539: E/AndroidRuntime(20193):    at dalvik.system.NativeStart.main(Native Method)

我重新创建片段我每次回到这个片段的时间,所以我不会被切换或类似的东西之前摧毁片段介意找到一种方法,只是忽略这个错误,例如说..任何人都得到了一个主意如何处理这个问题?

I recreate the Fragments every time I come back to this fragment, so I wouldn't mind to find a way to just ignore this error, for example by destroying the fragments before switching or something like that.. anyone got an idea how to handle this problem?

编辑:
好了一个解决这个问题的方法是使用

Okay one way to fix this is to use

mViewPager.setCurrentItem(0);

右键改变片段之前,这样的viewpager将开始一个新的事务,并在切换之前完成它

Right before changing the fragment, that way the viewpager will start a new transaction and finish it before switching

EDIT2:
还有一个办法解决它。

One more way to fix it

mViewPager.isDirty()

如果返回true,不要开关

if this returns true, dont switch

推荐答案

好吧来解决这个问题的一种方法是使用

Okay one way to fix this is to use

mViewPager.setCurrentItem(0);

右键改变片段之前,这样的viewpager将开始一个新的事务,并在切换之前完成它

Right before changing the fragment, that way the viewpager will start a new transaction and finish it before switching

这篇关于ViewPager里面片段FragmentPagerAdapter开始交易时,应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 17:40