跳转的方法:
1)简单跳转,没有带参的:
private void onClickLisener() {
// TODO Auto-generated method stub
btn_login_register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//意图、意向,参数1:表示当前在哪里,参数二:跳转到哪里
Intent intent=new Intent(MainActivity.this,Register.class);
//启动意图
MainActivity.this.startActivity(intent);
//关闭当前activity
MainActivity.this.finish();
}
});
1) 带参数跳
btn_register_reg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent=new Intent(Register.this,MainActivity.class);
String username=et_register_username.getText().toString();
String password=et_register_password.getText().toString();
int a=username.trim().length();
int b=password.trim().length();
if(a>0 && b>0){
intent.putExtra("username", username);
intent.putExtra("password", password);
startActivity(intent);
Register.this.finish();
}else{
//Toast.makeText(Register.this,"請輸入用戶名和大於8小於16位的密碼;", 2000);
System.out.println("错误!");
}
}
});
//接收参数:
private void intent() {
// TODO Auto-generated method stub
Intent intent=getIntent();
String username=intent.getStringExtra("username");
String password=intent.getStringExtra("password");
et_login_user.setText(username);
et_login_password.setText(password);
System.out.println(username);
System.out.println(password);
}