Android Studio中点击按钮跳转到其他页面

Android Studio中点击按钮跳转到其他页面:

private Button button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
     
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    button1 = (Button) findViewById(R.id.button);//
    button1.setOnClickListener(new View.OnClickListener() {
     
    @Override
    public void onClick(View v) {
     
            // TODO Auto-generated method stub
        Intent intent = new Intent();
        intent.setClass(MainActivity.this, Main2Activity.class);//this前面为当前activty名称,class前面为要跳转到得activity名称
        startActivity(intent);         
        }
    });
}

你可能感兴趣的:(Android,studio,移动开发,java,android)