title: Android Button click go to another xml page
body: <p>So what I've done in Eclipse, in layouts I have: activity_main.xml  and activity_main2.xml. What I tried is to create a button in activity_main.xml and on click to go on screen of activity_main2.xml</p>
  
  <p>so in <code>com.example.myfirstapp</code> I have</p>
  
  <p>MainActivity.Java:</p>
  
  <pre><code>package com.example.myfirstapp;
  
  import android.os.Bundle;
  import android.app.Activity;
  import android.content.Intent;
  import android.util.Log;
  import android.view.Menu;
  import android.view.View;
  
  public class MainActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.activity_main, menu);
          return true;
      }
  
      public void click1(View v) {
          Log.i("clicks","You Clicked B1");
          Intent i=new Intent(
                       MainActivity.this,
                       MainActivity2.class);
          startActivity(i);
      }
  }
  </code></pre>
  
  <p>MainActivity2.java</p>
  
  <pre><code>package com.example.myfirstapp;
  
  import android.os.Bundle;
  import android.view.Menu;
  import android.app.Activity;
  
  public class MainActivity2 extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main2);
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.activity_main, menu);
          return true;
      }
  }
  </code></pre>