Switching Views inside Activity

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

Switching Views inside Activity

Postby mangaluve » Mon Mar 30, 2009 9:29 am

When you make an Android application, is it common to only set the top-level view Once in every activity (i.e. something like setContentView(R.layout.xxx) in onCreate)? And if I want to change the UI I switch to another activity? Or is it common to switch views within the same activity? (because I didn't manage to switch from a linear layout containing some buttons to a linear layout containing a surface view).
mangaluve
Experienced Developer
Experienced Developer
 
Posts: 82
Joined: Mon Mar 23, 2009 8:59 pm

Top

Postby Teikan » Thu Apr 02, 2009 7:31 pm

Couldn't you accomplish a similar feat by just opening another activity in the stack? It seems to me, by what little i know of the programming, that dynamically altering an activity that's already in place gets a little messy.
Teikan
Freshman
Freshman
 
Posts: 9
Joined: Wed Jan 28, 2009 5:38 pm

Postby Yinten » Fri Apr 03, 2009 5:15 am

http://developer.android.com/guide/prac ... mance.html

action vs clock cycles
Add a local variable 1
Add a member variable 4
Call String.length() 5
Call empty static native method 5
Call empty static method 12
Call empty virtual method 12.5
Call empty interface method 15
Call Iterator:next() on a HashMap 165
Call put() on a HashMap 600
Inflate 1 View from XML 22,000
Inflate 1 LinearLayout containing 1 TextView 25,000
Inflate 1 LinearLayout containing 6 View objects 100,000
Inflate 1 LinearLayout containing 6 TextView objects 135,000
Launch an empty activity 3,000,000
Yinten
Developer
Developer
 
Posts: 27
Joined: Tue Jan 20, 2009 7:27 pm

Postby mangaluve » Fri Apr 03, 2009 10:15 am

Okey thanks..but why can't I switch from a layout I have in one XML file into another in another XML file? It doesnt work if I switch to a surface view for instance..
mangaluve
Experienced Developer
Experienced Developer
 
Posts: 82
Joined: Mon Mar 23, 2009 8:59 pm

Postby Sowmya » Tue Apr 07, 2009 1:13 pm

Hi,
Try using LayoutInflater class to create View Objects.

LayoutInflater layInflate=getLayoutInflater() ;
View testView=layInflate.inflate(R.layout.xxx, null);
setContentView(testView);

Then views can be switched within same activity..
Sowmya
Experienced Developer
Experienced Developer
 
Posts: 51
Joined: Fri Mar 06, 2009 7:49 am

Postby mangaluve » Tue Apr 07, 2009 9:22 pm

Thanks! But it does not work with a surface view..
mangaluve
Experienced Developer
Experienced Developer
 
Posts: 82
Joined: Mon Mar 23, 2009 8:59 pm

Top

Postby linkmaster_6 » Tue Apr 07, 2009 10:01 pm

Cant you just set the content view to a differnt view?

something like

If (var = true) { setContentView(View1) }
if (var = false) {setContentView(View2) }

its dirty and nasty but it works
linkmaster_6
Experienced Developer
Experienced Developer
 
Posts: 51
Joined: Thu Oct 16, 2008 8:52 pm

Postby mangaluve » Tue Apr 07, 2009 10:10 pm

Sorry if I was misleading; I can set the view, for instance by inflating it and using setContentView. The problem is that nothing is rendered, the screen is all black (if I, however, first set the surface view, some stuff is drawn). But if I first have one view (some buttons in a linear layout or whatever) and then switch to a SurfaceView, nothing happens..
mangaluve
Experienced Developer
Experienced Developer
 
Posts: 82
Joined: Mon Mar 23, 2009 8:59 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests