*edit*Sorry for the trouble, the reason for the bug was because I accidentally gave the findViewById(R.id.editTextemail2) to another edit text, which caused it to screw up.
I am trying to create a warning message to people who don't type in a proper email (no '.' or '@') and a second message to people who don't type the confirmation email exactly as the original. Can some one explain why my alert dialog only works for the first one and not the second one even though the code is nearly identical? The alert dialog is supposed to pop up once the person is done editing the text (leaves the edit text focus) Thanks!
email = (EditText) findViewById(R.id.editTextemail);
email2 = (EditText) findViewById(R.id.editTextemail2);
email.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View arg0, boolean hasFocus) {
// checks if it is a proper email
if (!hasFocus) {
if (!hasPeriod(email.getText().toString())
|| !hasAt(email.getText().toString())) {
new AlertDialog.Builder(CreateAccount.this)
.setTitle("Error")
.setMessage(
"Please enter a properly formatted email address to continue")
.setNeutralButton("OK", null).show();
}
}
}
});
email2.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View arg0, boolean hasFocus) {
// checks if it is a proper email
if (!hasFocus) {
if (!email.getText().toString()
.contentEquals(email2.getText().toString())) {
new AlertDialog.Builder(CreateAccount.this)
.setTitle("Error")
.setMessage(
"Please verify your email addresses match")
.setNeutralButton("O开发者_开发技巧K", null).show();
}
}
}
});
I think you should use equals instead of contentEquals
if (!email.getText().toString().equals(email2.getText().toString())) {
精彩评论