[android-developers] setContentView() twice on an activity?
Hi, What is the effect of calling setContentView() in an activity twice? My situation: class A extends Activity { protected TextView mLabel; public void onCreate() { super.onCreate(); setContentView(R.layout.a); mLabel = (TextView)findViewById(R.id.label); } } class B extends A { protected ImageView mImageView; public void onCreate() { super.onCreate(); setContentView(R.layout.b); mImageView = (ImageView)findViewById(R.id.photo); mLabel.setText(hello); } } this works, but not sure if it's ok to do this. Basically the parent activity initializes a bunch of stuff that B will use too, B just wants to add an additional ImageView for itself. So layout.a and layout.b are the same, they're a copy-paste of one another. B just has an extra ImageView appended. Thanks -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe, reply using remove me as the subject.
Re: [android-developers] setContentView() twice on an activity?
On Wed, Apr 14, 2010 at 12:28 PM, Mark Wyszomierski mar...@gmail.comwrote: What is the effect of calling setContentView() in an activity twice? Probably the second call overwrites the first. Why don't you try and find out? So layout.a and layout.b are the same, they're a copy-paste of one another. B just has an extra ImageView appended. This is terrible. You can reuse layouts by including an existing one in another. So layout b could just do: include:layout.a / (or whatever the XML syntax is, look it up) ImageView / - TreKing - Chicago transit tracking app for Android-powered devices http://sites.google.com/site/rezmobileapps/treking -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe, reply using remove me as the subject.
Re: [android-developers] setContentView() twice on an activity?
Why not just make the extra image invisible and set it visible when you need it? On Wed, Apr 14, 2010 at 12:25 PM, ~ TreKing treking...@gmail.com wrote: On Wed, Apr 14, 2010 at 12:28 PM, Mark Wyszomierski mar...@gmail.comwrote: What is the effect of calling setContentView() in an activity twice? Probably the second call overwrites the first. Why don't you try and find out? So layout.a and layout.b are the same, they're a copy-paste of one another. B just has an extra ImageView appended. This is terrible. You can reuse layouts by including an existing one in another. So layout b could just do: include:layout.a / (or whatever the XML syntax is, look it up) ImageView / - TreKing - Chicago transit tracking app for Android-powered devices http://sites.google.com/site/rezmobileapps/treking -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- Writing code is one of few things that teaches me I don't know everything. Make Call Girl Manager great! Join the forums. http://www.fuligin.com/forums -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe, reply using remove me as the subject.