Reputation: 21
Does anyone know what's wrong with my code, I'm trying to compare the input in my edit text field to ensure their equal value before it creates an account.
//compare the fields contents
if(editTextPassword.equals(editTextReEnterPassword)) {
//they are equal
//Creating a new user
firebaseAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()){
finish();
startActivity(new Intent(getApplicationContext(), Home.class));
} else{
Toast.makeText(Register.this, "Could not register... please try again", Toast.LENGTH_SHORT).show();
}
}
});
}else {//they are not equal
Toast.makeText(Register.this, "Passwords do not match... please try again", Toast.LENGTH_SHORT).show();
}
Upvotes: 0
Views: 370
Reputation: 3044
You have to get the text value of the edit text.
So, really, you can not do editText.equals()
You would do something like this..
String editTextPasswordString = editTextPassword.getText().toString().trim();
String editTextReEnterPasswordString = editTextReEnterPassword.getText().toString().trim();
if(editTextPasswordString.equals(editTextReEnterPasswordString)) {
//code
}
Upvotes: 2
Reputation: 102
First you need to get the value from EditText using the method getText().toString(), like this:
String newPassword= editTextReEnterPassword.getText().toString();
For more information about the method, please check the follow link: Get Value of EditText
After that, you need to compare the previous string editTextPassword with the new one created, which is the result of the method getText(), editTextReEnterPassword.
So your final code, should be like this:
String newPassword = editTextReEnterPassword.getText().toString();
String atualPassword = editTextPassword.getText().toString();
if(atualPassword.equals(newPassword))
{
...
}
else
{
...
}
Upvotes: 1
Reputation:
Try:
if(editTextPassword.getText().toString().equals(editTextReEnterPassword.getText().toString()))
EditText
is not a String
Upvotes: 0