On Wed, Jul 27, 2011 at 8:49 AM, MobileVisuals <eyv...@astralvisuals.com> wrote: > I try to add 2 views to a Viewflipper, but I get > > "java.lang.IllegalStateException: The specified child already has a > parent. > You must call removeView() on the child's parent first." > > when I try to add the view. I don't know why this happens. I try to > remove the view from the ViewFlipper, but I still get the same > message. How can I add a ViewFlipper to the layout? You can view my > code and XML layout below: > --------------------------------------------------- > setContentView(R.layout.lunar_layout); > mLunarView = (LunarView) findViewById(R.id.lunar); > ViewFlipper vf=(ViewFlipper) findViewById(R.id.flip); > vf.addView(mLunarView, 0);
The error should be self-explanatory. You already have R.id.lunar as a child of the LinearLayout. > layout: > ------------------------------------------------------------------ > <?xml version="1.0" encoding="utf-8"?> > > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/ > android" > android:layout_width="wrap_content" > android:layout_height="wrap_content"> > > <ViewFlipper > android:id="@+id/flip" > android:layout_width="fill_parent" > android:layout_height="fill_parent"/> > > <astral.effectsf.LunarView > android:id="@+id/lunar" > android:layout_width="fill_parent" > android:layout_height="fill_parent"/> > > > </LinearLayout> Make the LunarView be a child element of your ViewFlipper, and get rid of the Java code to try adding it to the ViewFlipper, and you will be set. Here are some projects demonstrating the use of a ViewFlipper: https://github.com/commonsguy/cw-android/tree/master/Fancy/Flipper1 https://github.com/commonsguy/cw-android/tree/master/Fancy/Flipper2 -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Android Training in NYC: http://marakana.com/training/android/ -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en