setContentView VS new activity. I can't get it.

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

setContentView VS new activity. I can't get it.

Postby daliz » Mon Aug 17, 2009 1:02 pm

In this thread I'd like to make clear some things that are driving me crazy.

Suppose I have a button. When I click this button I want to switch the shown layout from R.layout.main to R.layout.menu.

Now, on the click event, I used to make to happen a "setContentView(R.layout.menu)", but I've been discouraged to do this. Indeed I had some problems later. So I changed technique... and now I create and start a new Activity for every change of layout I need.

But I think it is a little insane. If I have a menu with 5 or more choices, I have to create 5 Activities and I think it's not normal for a "stupid" menu, not to mention the whole application (I could have dozens of activities!!).

Can anyone tell me where is my mistake?? How do you switch between multiple layouts in an easy and fast way??

Thank you.
~ daliz ~ :: www.datapixel.eu
w w w . g e e k d r o i d . c o m
daliz
Junior Developer
Junior Developer
 
Posts: 21
Joined: Tue Jul 07, 2009 11:15 pm

Top

Postby mangaluve » Mon Aug 17, 2009 1:21 pm

What problems are you experiencing when using setContentView multiple times? One disadvantage of it is, of course, that you get a lot of code in your Activity.
mangaluve
Experienced Developer
Experienced Developer
 
Posts: 82
Joined: Mon Mar 23, 2009 8:59 pm

Postby daliz » Mon Aug 17, 2009 1:37 pm

I can't remember where I had read it. This post, written by an Android staff developer (or at least so he said!), told about later issues that can occur using setContentView multiple times inside of the same activity.

Are you telling me you have been using this technique without problems? If it's so, it's great and I'll go back to this asap... =)
~ daliz ~ :: www.datapixel.eu
w w w . g e e k d r o i d . c o m
daliz
Junior Developer
Junior Developer
 
Posts: 21
Joined: Tue Jul 07, 2009 11:15 pm

Postby mangaluve » Mon Aug 17, 2009 1:53 pm

Well, yes and no. I've never really needed it but I did do some experiments with it. Some times it worked, sometimes it didn't :) I ran into a lot of problems when I mixed this with the usage of surface view for instance.

But it's not impossible. You can change everything without using setContentView. For instance using a ViewFlipper or ViewSwitcher or whatever they call it.
mangaluve
Experienced Developer
Experienced Developer
 
Posts: 82
Joined: Mon Mar 23, 2009 8:59 pm

Postby daliz » Mon Aug 17, 2009 2:57 pm

I think I solved all my problems with the ViewFlipper.
Thank you, mangaluve... :-)
~ daliz ~ :: www.datapixel.eu
w w w . g e e k d r o i d . c o m
daliz
Junior Developer
Junior Developer
 
Posts: 21
Joined: Tue Jul 07, 2009 11:15 pm

Postby WarrenFaith » Mon Aug 17, 2009 3:18 pm

Btw: I love to use Activities... each Activity exists for one reason and just for that... easiest modul-based development ever :)
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Top

Postby daliz » Mon Aug 17, 2009 4:23 pm

Yeah! I like using Activities too. But in my personal opinion, I think it's not good to over-use them since you have to setup the persistance, no-history etc. to keep the users from going back with the "back" button of the phone. And also for the increased complicances in passing parameters with putExtra and similars....!
~ daliz ~ :: www.datapixel.eu
w w w . g e e k d r o i d . c o m
daliz
Junior Developer
Junior Developer
 
Posts: 21
Joined: Tue Jul 07, 2009 11:15 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests