android的activity跳转到另一个activity

  HelloworldActivity.java:

  package com.example.helloworld;

  import android.app.Activity;

  import android.content.Intent;

  import android.view.View;//注意view的大小写

  import android.view.View.OnClickListener;

  import android.os.Bundle;

  import android.widget.Button;

  public class HelloworldActivity extends Activity {

  private Button my_button = null;

  @Override

  public void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  setContentView(R.layout.activity_helloworld);

  my_button = (Button)findViewById(R.id.my_button);

  my_button.setText( "Next" );

  my_button.setOnClickListener(new MyButtonListener());

  }

  class MyButtonListener implements OnClickListener{

  public void onClick(View v) {

  // TODO Auto-generated method stub

  Intent intent = new Intent();

  intent.setClass(HelloworldActivity.this, NextActivity.class);

  HelloworldActivity.this.startActivity(intent);

  }

  }

  /**

  * 如果下面的语句不要,那么系统运行的时候会直接进入本程序中,而不是先进入主菜单

  * 再进入选择应用程序界面进入本程序

  * 为了方便调试,这里就不进入主菜单界面了*/

  /*@Override

  public boolean onCreateOptionsMenu(Menu menu) {

  getMenuInflater().inflate(R.menu.activity_helloworld, menu);

  return true;

  }*/

  }

  NextActivity.java:

  package com.example.helloworld;

  import android.app.Activity;

  import android.os.Bundle;

  import android.widget.Button;

  public class NextActivity extends Activity{

  private Button my_button2 = null;

  @Override

  protected void onCreate(Bundle savedInstanceState) {

  // TODO Auto-generated method stub

  super.onCreate(savedInstanceState);

  setContentView(R.layout.activity_next);

  my_button2 = (Button)findViewById(R.id.my_button2);

  // my_button2.setText("@string/close"); //setText里面不能采用资源引用

  //资源引用显示文本应该是在xml中的

  my_button2.setText("Close");

  }

  }