Main代码如下:
package com.example.jack.myapplication; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends AppCompatActivity { private Button btn1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn1 = (Button) findViewById(R.id.button1); btn1.setOnClickListener(new MyOnClickListener() { @Override public void onClick(View view) { super.onClick(view); Intent intent = new Intent(); intent.setClass(MainActivity.this, Main2Activity.class); startActivity(intent); } }); } } class MyOnClickListener implements View.OnClickListener{ @Override public void onClick(View view){ } }
这个在进行实际应用的时候经常会用到,记录一下