点击按钮放入intent中 button31.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //在intent中关联两个activity Intent intent = new Intent(MainActivity.this,Main2Activity.class); //用键值对的形式将值放入intent中 intent.putExtra("userName",editText4.getText().toString()); intent.putExtra("password",editText5.getText().toString()); //启动activity startActivity(intent); } });
在第二activity中 从intent中获取 Intent intent = getIntent(); //根据第一中设置的id来获取
String userName = intent.getStringExtra("userName"); String password = intent.getStringExtra("password"); textView.setText(userName + password);