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.
Asked
Active
Viewed 3,766 times
3
-
This thread is similar http://stackoverflow.com/questions/3900044/clone-textview-to-append-it-to-a-viewgroup – Khaled Annajar Jan 16 '13 at 14:09
-
http://stackoverflow.com/a/15761866/884674 a workaround is at this link. – jeet.chanchawat Apr 30 '13 at 09:43
1 Answers
2
When using an xml layout you can define your view in another layout and use the <include ..>
directive to put it in several places multiple times.

Franci Penov
- 74,861
- 18
- 132
- 169

Moritz
- 10,124
- 7
- 51
- 61
-
I suspect Mr. Reaper meant "use the `
` 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 Feb 28 '10 at 13:29 -
Well i am new this Android API, so dont know this
directive but the `cannot do` is true... as i tried doing the same, i got runtime error – Amit Mar 02 '10 at 04:56 -
So, is there any way to clone a view from a view hierarchy already inflated at runtime, and use it elsewhere... – Amit Mar 02 '10 at 05:15
-