1. Introducing Channels - a new way to chat with other Android users!
    Dismiss Notice

Change from one layout view to another and going back?

Last Updated:

  1. lugopaco

    lugopaco Active Member This Topic's Starter

    Mar 31, 2011
    Likes Received:
    Hi!!! want to make an Android app that starts with a "main" layout and when you push a button (called stateboton) that is in this layout the layout changes to a "main2" layout containing another button (called boton2), and when you push this one you get back to the first main.

    I want to do this in the same activity with out creating or starting another one.

    Here I show you part of the code:
    Code (Text):
    2.     public class NuevoshActivity extends Activity
    3.     implements SensorEventListener,  OnClickListener {
    4.         private Button stateButton;
    5.         private Button boton2;
    7.     /** Called when the activity is first created. */
    8.       @Override
    9.       public void onCreate(Bundle savedInstanceState) {
    10.     super.onCreate(savedInstanceState);      
    11.     setContentView(R.layout.main);
    12.     this.stateButton = (Button)this.findViewById(R.id.boton);
    13.     this.boton2= (Button)this.findViewById(R.id.boton2);      
    14.     stateButton.setOnClickListener(this);
    15.     boton2.setOnClickListener(this);
    16.     }
    19.     @Override
    20.     public void onClick(View v) {
    21.      if(v==stateButton) {
    22.     setContentView(R.layout.main2);              
    23.     }
    24.     else if(v==boton2) {
    25.     setContentView(R.layout.main);
    26.     }
    27.     }
    28.     }
    The mains only have some images, text views and the buttons.

    But I've some troubles. Can't it just be as simple as that or what am I missing or what is wrong?


Share This Page