SapphireSun
SapphireSun

Reputation: 9388

How do I clone a View?

My question is almost exactly this question:

Clone textview to append it to a ViewGroup

However, I was inflating a view, and then attempting to clone it at the object level for performance reasons (I don't want to parse XML every single time), so that answer doesn't help me. View.clone() is protected and it apparently doesn't have a copy constructor. Is there any way to do this?

Upvotes: 73

Views: 59169

Answers (1)

Romain Guy
Romain Guy

Reputation: 98501

You cannot clone views, the way to do it is to inflate your View every time. Note that the XML is compiled into binary which can be parsed very efficiently.

Upvotes: 111

Related Questions