you are not switching from activity to another activity. u r just changing the view. for switching b/n activities u should use intents.
as for ur exception i guess it says the specified child has a parent, since ur tries to set the view R.layout.main twice in ur code. so first remove the view and then add it when the button b2 is clicked. On Tue, Mar 23, 2010 at 5:00 PM, Ramji <[email protected]> wrote: > Hi, > I just started programmind an application using Eclipse for Android. > I am creating 2 screens. > > 1st screen: > Has a button which onClick --> takes you to the 2nd screen. > > 2nd screen: > Has a button which onClick -- > takes you to the 1st screen. > > just like NEXT and BACK. > > But somehow i keep getting "Application Simple application has > stopped > unexpectedly." Force Close. > > > My code:Simple.java > > package com.sample; > > import android.app.Activity; > import android.os.Bundle; > import android.view.View; > import android.view.View.OnClickListener; > import android.widget.Button; > > public class sample extends Activity { > /** Called when the activity is first created. */ > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > > Button b1 = (Button)findViewById(R.id.button1); > > b1.setOnClickListener(new OnClickListener() { > public void onClick(View v) > { > setContentView(R.layout.main1); > > Button b2 = (Button)findViewById(R.id.button2); > > b2.setOnClickListener(new OnClickListener() { > public void onClick(View v1) > { > setContentView(R.layout.main); > } > }); > } > }); > } > } > > Can any once tell what went wrong or what is the best way to do it? > > Thanks > > -- > You received this message because you are subscribed to the Google > Groups "Android Beginners" group. > > NEW! Try asking and tagging your question on Stack Overflow at > http://stackoverflow.com/questions/tagged/android > > To unsubscribe from this group, send email to > [email protected]<android-beginners%[email protected]> > For more options, visit this group at > http://groups.google.com/group/android-beginners?hl=en > > To unsubscribe from this group, send email to android-beginners+ > unsubscribegooglegroups.com or reply to this email with the words "REMOVE > ME" as the subject. > -- You received this message because you are subscribed to the Google Groups "Android Beginners" group. NEW! Try asking and tagging your question on Stack Overflow at http://stackoverflow.com/questions/tagged/android To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en To unsubscribe from this group, send email to android-beginners+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

