Switching Of Screens

by Rachna » Wed, 25 Jun 2008 19:17:32 GMT

Sponsored Links
 Hello Friends

When i started making an application in android i designed two
in res/layout.
Then i made every java file in my package extending Activity....
I mean i made two java classes:-
1.TermsScreen.java extends Activity
2.LoginScreen.java extends Activity
And then to switch between these two i used INTENT and it worked out.


But now i want to change my code...
I want that there should be only one class that extends Activity(say
And then i want the two classes TermsScreen.java and LoginScreen.java
should get reference of that main_activity class.

I wrote code for all this and again made use of INTENT for switching
but its not working.
Can anyone please tell me will INTENT work or should i use something
else to go from TermsScreen.java to LoginScreen.java

Thanks in advance


Switching Of Screens

by Mark Murphy » Wed, 25 Jun 2008 19:42:26 GMT

 > But now i want to change my code...

Intents are for switching between activities (among other uses), not for
changing the UI of a single activity.

You can try calling setContentView() to the new UI when it is time to
switch, but I am not certain that will work.

What will work is to use ViewFlipper or another concrete ViewGroup
subclass. These work like tabbed windows (i.e., multiple discrete
"screens"), just without the actual tabs -- you are responsible for
switching between them as needed. It will require some reworking of your
code, such as perhaps combining the two layout XML files into one.

The Animation2.java sample in the ApiDemos with the SDK uses ViewFlipper.

Mark Murphy (a Commons Guy)
_The Busy Coder's Guide to Android Development_ -- Available Now!


Sponsored Links