第一个程序:activity1 package Android1.Home; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; public class activity1 extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { /** * 内部类实现按钮响应 * Listener的实现要在setOnClickListener前面。 * 如果在后面的话,会set进去一个null,也就不响应了。 */ OnClickListener MyButtonListener = new OnClickListener(){ public void onClick(View v){ //生成一个Intent对象 Intent intent = new Intent(); intent.setClass(activity1.this, activity2.class); activity1.this.startActivity(intent); } }; super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView myTextView = (TextView)findViewById(R.id.myTextView); Button myButton = (Button)findViewById(R.id.myButton); myTextView.setText("按钮一"); myButton.setText("我的第一个按钮"); myButton.setOnClickListener(MyButtonListener); //内部类无括号 } } 第二个程序:activity2 package Android1.Home; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; public class activity2 extends Activity{ /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { OnClickListener MyButtonListener = new OnClickListener(){ public void onClick(View v){ //生成一个Intent对象 Intent intent = new Intent(); intent.setClass(activity2.this, activity1.class); activity2.this.startActivity(intent); } }; super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView myTextView = (TextView)findViewById(R.id.myTextView); myTextView.setText("按钮二"); Button myButton = (Button)findViewById(R.id.myButton); myButton.setText("回转"); myButton.setOnClickListener(MyButtonListener); //内部类无括号 } }