0

I have a child linearlayout created programmatically and added on a parent linearlayour programmatically.

parentlayout.addView(childlayout)

But, the I want to add again the child layout to another linearlayout, it returns an error, is it possible? What is the best way to do that?

  • 2
    Possible duplicate of [Creating LinearLayout Programmatically/Dynamically with Multiple Views](http://stackoverflow.com/questions/20283723/creating-linearlayout-programmatically-dynamically-with-multiple-views) – Yaw Asare Jan 11 '16 at 04:07
  • 1
    No, you need to either remove it's parent or create another instance and add that to the other parent LL – codeMagic Jan 11 '16 at 04:07
  • have solved this ? or there is still some issue left ? – Shree Krishna Jan 21 '16 at 13:41

2 Answers2

1

Create another instance of the same class, and set the same properties. I mean Inflate your View again if needed. Because A single View cannot be a child of two ViewGroup parents.

Shree Krishna
  • 8,474
  • 6
  • 40
  • 68
1

Each view can have only one parent possible. So you can not add same child to another linear layout. What you can do is make another instance, apply same properties which you given to previous child. and then add this instance to the parent view.

Deepak
  • 756
  • 4
  • 10