How do I clone a View?

SapphireSun picture SapphireSun · Nov 11, 2010 · Viewed 52.1k times · Source

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?

Answer

Romain Guy picture Romain Guy · Nov 11, 2010

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.