Thanks for your response.

What happens to the ids of the elements in the layout? Will I have one id
for the TextViews in my example, so when I do something to it (change the
color or text, for example), will all the TextViews in all the layouts
change? I guess it will not matter on a small screen as there will only be
one activity at time.

What if I use fragments and have two fragments on the screen at the same
time with the same layout for each fragment. Then there are two active
TextViews with the same id....is this an issue? If I change one, will both
change?

Thanks!

Mark

On Tue, Oct 30, 2012 at 3:56 PM, Romain Guy <[email protected]> wrote:

> 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

-- 
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

Reply via email to