开发者

ViewSwitcher can't remove the child view?

I removed all child view from the ViewSwitcher by

mSwitcher.removeAllViews();

But when I add a previously removed view back, it throws an java.lang.IllegalStateException and says I haven't remove this view from its parent.

Here is the code:

View curView = mSwitcher.getCurrentView();

mSwitcher.removeAllViews();

Log.d(TAG, "parent >> " + nextView.getParent());
Log.d(TAG, "switcher >> " + mSwitcher);
mSwitcher.addView(curView);
mSwitcher.addView(nextView);

mSwitcher.showNext();

the Exception has thrown in this line

mSwitcher.addView(nextView);

Here is the log:

09-03 10:04:14.551 D/MainActivity( 8852): parent >> null
09-03 10:04:14.551 D/MainActivity( 8852): switcher >> android.widget.ViewSwitcher@43ebb580
09-03 10:04:14.551 D/AndroidRuntime( 8852): Shutting down VM
09-03 10:04:14.551 W/dalvikvm( 8852): threadid=1: thread exiting with uncaught exception (group=0x4001d7e8)
09-03 10:04:14.571 E/AndroidRuntime( 8852): FATAL EXCEPTION: main
09-03 10:04:14.571 E/AndroidRuntime( 8852): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
09-03 10:04:14.571 E/AndroidRuntime( 8852):     at android.view.ViewGroup.addViewInner(ViewGroup.java:1970)
09-03 10:04:14.571 E/AndroidRuntime( 8852):     at android.view.ViewGroup.addView(ViewGroup.java:1865)
09-03 10:04:14.571 E/AndroidRuntime( 8852):     at android.widget.ViewAnimator.addView(ViewAnimator.java:160)
09-03 10:04:14.571 E/AndroidRuntime( 8852):     at android.widget.ViewSwitcher.addView(ViewSwitcher.java:66)
09-03 10:04:14.571 E/AndroidRuntime( 8852):     at android.view.ViewGroup.addView(ViewGroup.java:1822)
09-03 10:04:14.571 E/AndroidRuntime( 8852):     at android.view.ViewGroup.addView(ViewGroup.java:1802)
09-03 10:04:14.571 E/AndroidRuntime( 8852):     at com.aimi.appstore.tulipa.ui.activity.MainActivity.setSelected(MainActivity.java:104)
09-03 10:04:14.571 E/AndroidRuntime( 8852):     at com.aimi.appstore.tulipa.ui.activity.MainActivity$2.onClick(MainActivity.java:54)
09-03 10:04:14.571 E/AndroidRuntime( 8852):     at android.view.View.performClick(View.java:2408)
09-03 10:04:14.571 E/AndroidRuntime( 8852):     at android.view.View$PerformClick.run(View.java:8818)
09-03 10:04:14.571 E/AndroidRuntime( 8852):     at android.os.Handler.handleCallback(Handler.java:587)
09-03 10:04:14.571 E/AndroidRuntime( 8852):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-03 10:04:14.571 E/AndroidRuntime( 8852):     at android.os.Looper.loop(Looper.java:123)
09-03 10:04:14.571 E/AndroidRuntime( 8852):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-03 10:04:14.571 E/AndroidRuntime( 8852):     at java.lang.reflect.Method.invokeNative(Native Method)
09-03 10:04:14.571 E/AndroidRuntime( 8852):     at java.lang.reflect.Method.invoke(Method.java:521)
09-03 10:04:14.571 E/AndroidRuntime( 8852):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-03 10:04:14.571 E/AndroidRuntime( 8852):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-03 10:04:14.5开发者_C百科71 E/AndroidRuntime( 8852):     at dalvik.system.NativeStart.main(Native Method)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜