Today in the course of the design, because adapter inside the dynamic add view, wrote the following code
TextView start = new TextView (context,null); Holder.start = start; Linearlayout.layoutparams Startl = new Linearlayout.layoutparams (80,40); Start.setlayoutparams (STARTL); Start.settext ("(" +bean.getstart () + ")");((ViewGroup) convertview). AddView (start);(viewgroup) convertview). AddView (start);
the results logcat an error.
Java.lang.IllegalStateException:The specified child already have a parent. You must call Removeview () on the child ' s parent first.
The reason is: Instantiate a layout (start) and then be added to ViewGroup two times by me. However, a view can have only one parent control. When you add the second time, the view goes to change the control's parent control. But Android does not allow a child control that already has a parent control to change his parent control at run time.
AddView easy-to-throw error when adding layouts dynamically