MainActivity:
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button submit = (Button)findViewById(R.id.submit);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String user = ((EditText)findViewById(R.id.user)).getText().toString();
String psw = ((EditText)findViewById(R.id.pwd)).getText().toString();
String repsw = ((EditText)findViewById(R.id.repwd)).getText().toString();
String email = ((EditText)findViewById(R.id.email)).getText().toString();// TODO Auto-generated method stub
if((!"".equals(user))&&(!"".equals(psw))&&(!"".equals(repsw))){
if(!psw.equals(repsw)){
Toast.makeText(MainActivity.this, "两次输入的密码不同", Toast.LENGTH_SHORT).show();
((EditText)findViewById(R.id.pwd)).setText("");
((EditText)findViewById(R.id.repwd)).setText("");
// 让密码编辑框获得焦点
((EditText)findViewById(R.id.pwd)).requestFocus();//if(!pwd.e)
}
else{
Intent intent = new Intent(MainActivity.this,RegisterActivity.class);
// 创建并实例化一个bundle
Bundle bundle = new Bundle();
bundle.putCharSequence("user", user);
bundle.putCharSequence("psw", psw);
bundle.putCharSequence("email", email);
intent.putExtras(bundle);
startActivity(intent);
}
}else {
Toast.makeText(MainActivity.this, "请将信息输入完整", Toast.LENGTH_SHORT).show();
}
}
});
RegisterActivity:
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
// 获取Intent对象
Intent intent=getIntent();
// 获取传递的数据包
Bundle bundle=intent.getExtras();
TextView user= (TextView)findViewById(R.id.user);
user.setText("用户名:"+bundle.getString("user"));
TextView pwd=(TextView)findViewById(R.id.pwd);
pwd.setText("密码: "+bundle.getString("psw"));
TextView email=(TextView)findViewById(R.id.email);
email.setText("E-mail:"+bundle.getString("email"));