3

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.

Amit
  • 1,128
  • 6
  • 15
  • 29

1 Answers1

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
  • yeah sorry the include tag has been swallowed by the syntax formatter. – Moritz Mar 02 '10 at 16:23