title: Turn/flip for the two layouts with button click
body: <p>I have two layouts(xml files) and I want to flip from one page to another, the two xml files are main.xml and register.xml, if I click signin button in main.xml the page should turn and show register.xml  and also in register.xml if I click the submit button it  should turn to main.xml I tried a lot with the activity and i coldnt do it as I am new to android</p>
  
  <p>please someone  share the code for me,</p>
  
  <p>here is my two xml codes</p>
  
  <p>main.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:gravity="center_horizontal"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:background="@drawable/background" &gt;
  
      &lt;LinearLayout
      android:orientation="horizontal" 
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="10dp" android:background="@drawable/loginapp"&gt;
   &lt;Button  android:layout_width="49px"  android:layout_height="44px" android:background="@drawable/login_home_btn_over_green" android:id="@+id/widget38"&gt;&lt;/Button&gt;
      &lt;/LinearLayout&gt;
  
      &lt;RelativeLayout android:id="@+id/relativeLayout1" android:gravity="center" android:layout_marginTop="25dip" android:layout_height="177dip" android:background="@drawable/login_form_bg_green" android:layout_width="296dip"&gt;
       &lt;EditText android:layout_marginRight="0dip"  android:id="@+id/userNameBox" android:layout_width="200px" android:background="@android:drawable/editbox_background" android:maxLines="1" android:layout_marginLeft="85dip" android:inputType="text" android:layout_height="wrap_content"&gt;&lt;/EditText&gt;
       &lt;EditText android:layout_marginRight="0dip"  android:id="@+id/passwordBox" android:layout_width="200px" android:background="@android:drawable/editbox_background" android:maxLines="1" android:layout_marginTop="45dip" android:layout_marginLeft="85dip" android:inputType="text|textVisiblePassword" android:layout_height="wrap_content"&gt;&lt;/EditText&gt;
      &lt;/RelativeLayout&gt;
  
      &lt;LinearLayout android:id="@+id/ll_three" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_below="@+id/ll_two" android:gravity="center"&gt;
        &lt;Button 
          android:text="Sign In"
          android:id="@+id/Button01"
          android:layout_width="wrap_content" 
          android:layout_marginTop="5dip"
          android:layout_marginRight="15dip"
          android:layout_height="wrap_content"/&gt;
      &lt;Button 
          android:layout_height="wrap_content" 
          android:layout_width="wrap_content" 
          android:layout_marginTop="5dip"
          android:id="@+id/Button02"
          android:text="New user"/&gt;
   &lt;/LinearLayout&gt;
  
     &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>register.xml is</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:stretchColumns="0"&gt;
  
      &lt;TableRow&gt;
       &lt;TextView android:id="@+id/TextView"   
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text=" REGISTER:"/&gt;    
      &lt;/TableRow&gt;
  
      &lt;TableRow&gt;
          &lt;TextView android:id="@+id/TextView01"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="First Name:"/&gt;
      &lt;EditText android:layout_marginRight="0dip"
        android:id="@+id/userNameBox" android:background="@android:drawable/editbox_background"
          android:maxLines="1" android:layout_marginLeft="15dip"   android:layout_weight="1"
          android:inputType="text" android:layout_height="35px" android:layout_width="0dip"&gt;&lt;/EditText&gt;
  
  
      &lt;/TableRow&gt;
  
      &lt;TableRow&gt;
      &lt;TextView android:id="@+id/TextView02"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Last Name:"/&gt;
      &lt;EditText android:layout_marginRight="0dip"
        android:id="@+id/userNameBox" android:layout_width="200px"  android:layout_weight="1" 
        android:background="@android:drawable/editbox_background" android:maxLines="1"
         android:layout_marginLeft="15dip" android:inputType="text" 
         android:layout_height="35px"&gt;&lt;/EditText&gt;
      &lt;/TableRow&gt;
  
  
      &lt;TableRow&gt;
          &lt;TextView android:id="@+id/TextView03"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Email:"/&gt;
      &lt;EditText 
       android:id="@+id/userNameBox" android:layout_width="200px"
        android:background="@android:drawable/editbox_background"  android:layout_weight="1"
         android:maxLines="1" android:layout_marginLeft="15dip" android:layout_marginRight="0dip"  
         android:inputType="text" android:layout_height="35px"&gt;
         &lt;/EditText&gt;
      &lt;/TableRow&gt;
  
      &lt;TableRow&gt;
       &lt;TextView android:id="@+id/TextView03"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Mobile No:"/&gt;
      &lt;EditText android:layout_marginRight="0dip" 
       android:id="@+id/userNameBox" android:layout_width="200px"   android:layout_weight="1"
        android:background="@android:drawable/editbox_background"
         android:maxLines="1" android:layout_marginLeft="15dip"
          android:inputType="text" android:layout_height="35px"&gt;
          &lt;/EditText&gt;
  
      &lt;/TableRow&gt;
  
  
  
    &lt;TableRow&gt;
    &lt;Button 
          android:layout_height="wrap_content" 
          android:text="Register"
          android:id="@+id/Button01"
            android:padding="3dip"
            android:layout_marginLeft="45dip"
            android:layout_marginRight="90dip"
            android:layout_marginTop="15dip"
            android:layout_column="1"
  
            android:layout_width="fill_parent" 
            android:layout_weight="1"/&gt;
    &lt;/TableRow&gt;
  &lt;/TableLayout&gt;
  </code></pre>
  
  <p>HERE ARE MY JAVA FILES</p>
  
  <p>login.java</p>
  
  <pre><code>package com.android;
  
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  
  public class Login extends Activity {
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          Button next = (Button) findViewById(R.id.Button02);
          next.setOnClickListener(new View.OnClickListener() {
              public void onClick(View view) {
                  Intent myIntent = new Intent(view.getContext(), Register.class);
                  startActivityForResult(myIntent, 0);
              }
  
          });
      }
  }
  </code></pre>
  
  <p>Register.java</p>
  
  <pre><code>package com.android;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  
  public class Register extends Activity {
  
      /** Called when the activity is first created. */
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.register);
  
          Button next = (Button) findViewById(R.id.Button01);
          next.setOnClickListener(new View.OnClickListener() {
              public void onClick(View view) {
                  Intent intent = new Intent();
                  setResult(RESULT_OK, intent);
                  finish();
              }
  
          });
      }}
  </code></pre>