John Ranniel Sinel
John Ranniel Sinel

Reputation: 87

How can I add again a programmatically created linearlayout to another linearlayout

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?

Upvotes: 0

Views: 91

Answers (2)

Deepak
Deepak

Reputation: 774

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.

Upvotes: 1

Shree Krishna
Shree Krishna

Reputation: 8562

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.

Upvotes: 1

Related Questions