在Android 8.1和9.0版中运行我的应用程序时,出现“AdapterView不支持removeView(View)”异常。在以前的版本中,它运行良好。尽管错误是一致的,但不会100%地发生(这使我怀疑这是线程问题),也不是特定于特定适配器或 ListView 的。例如,我从多个 Activity 对象访问相同的代码,它对某些 Activity 有效,而对其他 Activity 总是失败。我还应该指出,在出现错误的任何情况下,我都不会调用removeView。以下是该异常的LogCat输出:
java.lang.UnsupportedOperationException: removeView(View) is not supported in AdapterView
at android.widget.AdapterView.removeView(AdapterView.java:531)
at android.view.ViewOverlay$OverlayViewGroup.add(ViewOverlay.java:195)
at android.view.ViewGroupOverlay.add(ViewGroupOverlay.java:72)
at android.transition.TransitionUtils.createViewBitmap(TransitionUtils.java:170)
at android.transition.TransitionUtils.copyViewImage(TransitionUtils.java:104)
at android.transition.Visibility.onDisappear(Visibility.java:380)
at android.transition.Visibility.createAnimator(Visibility.java:249)
at android.transition.Transition.createAnimators(Transition.java:732)
at android.transition.TransitionSet.createAnimators(TransitionSet.java:396)
at android.transition.Transition.playTransition(Transition.java:1779)
at android.transition.TransitionManager$MultiListener.onPreDraw(TransitionManager.java:315)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:977)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2349)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1392)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6752)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
谁能指出我的解决方案?
最佳答案
我最终继承了ListView的子类,并使用空方法覆盖了removeView和addView。我怀疑这是解决此问题的正确方法,但它确实有效。