Search code examples
androidviewclone

Android views as templates


I want to create an android Layout of which I want to instantiate several copies. I understand that declaring the layout in an XML will create a single instance. Is there a way to use the XML View declaration as a 'definition' rather than a 'declaration' ? Or is it possible to clone a view ?

Thanks;


Solution

  • What do you mean by instantiate several copies? In the same activity? Or in different activities?

    You can inflate a layout using the LayoutInflater. This will allow you to create multiple instances of the view in the same activity.

    If you are create a list of information, where each list item has the same layout you can use a ListView, which will do the inflating for you.