You can reuse XML layouts (just like you can reuse any resource.) When you use a layout resource (with setContentView() for instance) it gets "inflated." This means the layout is parsed and converted into actual View objects. If you reuse the same layout in several activities, you will simply create several sets of View objects that all have the same characteristics.
On Tue, Oct 30, 2012 at 3:49 PM, Mark Phillips <[email protected]>wrote: > As a newbie, I was wondering if layouts are reusable. For example, say I > have Activities A and B, and they both have the same layout for the screen. > So I create Layout L in the file my_layout.xml, which has a Textfield with > @id+/textfield1 in the layout and it is blank. > > In the onCreate() of both Activities A and B, can I have the line > setContentView(R.my_layout)? Will there be any issues when switching from > one Activity to the other? > > Will I have issues accessing the Textfield with id textfiel1? If the user > sets the value Activity A and I save it somewhere (say in the Application > object), then when I display Activity B, textfield1 should be blank. Right? > > Other than one less layout file, am I really saving any resources by > having one layout file? > > Or, is it better practice to create two layout files, one for each > Activity, and to have two unique textfields in these two layouts. > > Thanks, > > Mark > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- Romain Guy Android framework engineer [email protected] -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

