Text doesn’t change in variable after pressing button in Android

For a little android project I’m making a loginscreen. I have variables, but they stay empty once I fill them in and press the button.

these are my variables:

private EditText email;
private EditText wachtwoord;
private Button loginButton;

here I fill them:

        email = (EditText)findViewById(R.id.emailInput);
        wachtwoord = (EditText)findViewById(R.id.wachtwoordInput);
        loginButton = (Button)findViewById(R.id.loginButton);
        
        }
}

and my method which always executes the catch code

    public void login(View view)
    {
        
        try {
        
        if(email.getText().toString() == "[email protected]" && wachtwoord.getText().toString() == "admin")
        {
            Toast.makeText(getApplicationContext(), "gelukt", Toast.LENGTH_SHORT).show();
        }
        else
        {
            Toast.makeText(getApplicationContext(), "mislukt", Toast.LENGTH_SHORT).show();
            loginButton.setEnabled(false);
        }
        

Answer

Change this line:

if(email.getText().toString() == "[email protected]" && wachtwoord.getText().toString() == "admin")

to this:

if(email.getText().toString().equals("[email protected]") && wachtwoord.getText().toString().equals("admin"))

Leave a Reply

Your email address will not be published. Required fields are marked *