jeudi 29 septembre 2016

If condition is not evaluated

When running, it does not match the condition.
It skips it and runs the "else" block.

Could you help me?

public class LoginActivity extends AppCompatActivity {

private EditText usern;
private EditText passw;
private Button logButton;

@Override
protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    usern = (EditText) findViewById(R.id.userNameText);
    passw = (EditText) findViewById(R.id.passwordText);
    logButton = (Button) findViewById(R.id.loginButton);

    logButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            if(usern.getText().toString().equals("demo") && passw.getText().equals("demo")){
                Intent intent = new Intent(LoginActivity.this, MainActivity.class);
                startActivity(intent);
                Toast.makeText(getApplicationContext(), "Login...", Toast.LENGTH_SHORT).show();
            }
            else{
                Toast.makeText(getApplicationContext(), "Username or password incorrect", Toast.LENGTH_SHORT).show();
            }
        }
    });
}
}

Aucun commentaire:

Enregistrer un commentaire