views:

162

answers:

1

I like to know how can i clone a view object which is already there in the view hierarchy, so that it can be added to the same view hierarchy again.

+1  A: 

When using an xml layout you can define your view in another layout and use the directive to put it in several places multiple times.

Soulreaper
I suspect Mr. Reaper meant "use the `<include>` directive" -- XML tags get eaten unless formatted as source code. You can also manually inflate such layouts using `getLayoutInflater()` and add them to a `ViewGroup`. What you cannot do is clone an existing in-Java view hiearchy -- at least, there does not appear to be any built-in code to do that.
CommonsWare
Well i am new this Android API, so dont know this <include> directive but the `cannot do` is true... as i tried doing the same, i got runtime error
Amit
So, is there any way to clone a view from a view hierarchy already inflated at runtime, and use it elsewhere...
Amit
yeah sorry the include tag has been swallowed by the syntax formatter.
Soulreaper