2
我有一個FragmentPagerAdapter在一個片段內,我顯示在一個FrameLayout內的ViewPager。 到目前爲止,一切正常,我可以在我的FrameLayout內部的碎片之間進行切換,完全沒有任何問題。ViewPager與FragmentPagerAdapter裏面碎片崩潰應用程序啓動時事務
,但如果我輕彈ViewPager,然後快速交換到不同的片段中期的動畫,我這個錯誤,應用程序崩潰:
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)
我重新創建片段我每次回到這個片段的時間,所以我不介意找到一種方法來忽略這個錯誤,例如在切換之前破壞碎片或類似的東西..任何人都知道如何處理這個問題?
編輯:解決這個 好的一個方法是使用
mViewPager.setCurrentItem(0);
右鍵改變片段之前,這樣的viewpager將啓動一個新的事務,並切換
EDIT2前完成它: 還有一個辦法解決它
mViewPager.isDirty()
如果返回true,不切換