我对安卓很陌生。我正在尝试开发一个用于练习的登录表单,但我无法将 2 个值传递和显示给另一个活动
Intent intent = new Intent(this, Success.class);
EditText edituser = (EditText) findViewById(R.id.userinput);
EditText editpass= (EditText) findViewById(R.id.passinput);
String username = edituser.getText().toString();
String password = editpass.getText().toString();
intent.putExtra(EXTRA_USER, username);
intent.putExtra(EXTRA_PASSWORD, password);
startActivity(intent);
目标活动是
Intent intent = getIntent();
String username = intent.getStringExtra(MainActivity.EXTRA_USER);
String password = intent.getStringExtra(MainActivity.EXTRA_PASSWORD);
// Create the text view
TextView userView = new TextView(this);
TextView passView = new TextView(this);
userView.setTextSize(40);
userView.setText(username);
passView.setTextSize(40);
passView.setText(password);
// Set the text view as the activity layout
setContentView(userView);
setContentView(passView);