我正在开发注册功能,我需要在注册前进行一些验证。因此,当我检查所有 editText 为 null 时,它就不起作用了。我不明白为什么。
这里的代码
public class RegisterActivity extends Activity implements View.OnClickListener {
private AlertDialogManager alert = new AlertDialogManager();
private EditText mFullName;
private EditText mEmail;
private EditText mPassword;
private EditText mPasswordAgain;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
init();
}
private void init() {
findViewById(R.id.registerButton).setOnClickListener(this);
mFullName = (EditText)findViewById(R.id.registerFullName);
mEmail = (EditText)findViewById(R.id.registerEmail);
mPassword = (EditText)findViewById(R.id.registerPassword);
mPasswordAgain = (EditText)findViewById(R.id.registerPasswordRetype);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.registerButton:
System.out.println("fullname="+mFullName.getText());
System.out.println("email="+mEmail.getText());
System.out.println("emailString="+mEmail.getText().toString());
if (mFullName.getText().toString().equals("") && mEmail.getText().toString().equals("") && mPassword.getText().toString().equals("") && mPasswordAgain.getText().toString().equals("")){
if (Utils.isValidEmail(mEmail.getText().toString())){
if (Utils.checkPassWordAndConfirmPassword(mPassword.getText().toString(), mPasswordAgain.getText().toString())){
register();
} else {
alert.showAlertDialog(RegisterActivity.this, "Error",
"Password doesn't match", false);
}
} else {
alert.showAlertDialog(RegisterActivity.this, "Error",
"Wrong email", false);
}
} else {
alert.showAlertDialog(RegisterActivity.this, "Error",
"All fields are required", false);
}
break;
}
}
}
单击按钮时,您会看到有 System.out.println。我也把它放在这里,但是
08-01 11:34:46.830: INFO/System.out(10434): fullname=
08-01 11:34:46.830: INFO/System.out(10434): email=
08-01 11:34:46.830: INFO/System.out(10434): emailString=
如果 getText 为空,它不会打印 null 吗?