package com.example.administrator.demo2;
import android.app.AlertDialog;
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.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
//调用父类的onCreate方法
super.onCreate(savedInstanceState);
//设置layout中对应的XML文件activity_main
setContentView(R.layout.activity_main);
//获取登录按钮
Button ligin_button = (Button) findViewById(R.id.Login);
//获取文本框控件
final EditText userName_edt = (EditText) findViewById(R.id.UserName);
final EditText userPass_edt = (EditText) findViewById(R.id.UserPassWord);
//设置“登录”按钮的监听事件
ligin_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String userName = userName_edt.getText().toString();
String userPass = userName_edt.getText().toString();
//获取Text控件
TextView tv = (TextView) findViewById(R.id.TextView);
//设置Text为本两个文本框的内容
tv.setText("您的用户名是:"+userName+"密码是:"+userPass);
//设置点击登录按钮后跳转到其他地方
Intent it = new Intent();
it.setClass(MainActivity.this,Main2Activity.class);
startActivity(it);
}
});
}
}