login.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
if( username_text.getText().toString() == "admin" &&
pass_text.getText().toString() == "password"){
startActivityForResult(i, ACTIVITY_CREATE);
}else{
Toast.makeText(gps_gui.this, "Your username or password is not correct! Please, insert again",
Toast.LENGTH_SHORT).show();
clearEditText();
}
}
});
I'm try to check it, I found it not go to if condition.
When using java, you must compare Strings using the String.equals(String) method. The == comparison checks to see if the String object values are equal, which undoubtedly they are not. Try to change you example to :
"admin".equals(username_text.getText().toString()) &&"password".equals(pass_text.getText().toString())
Its also smart to put the static string first, in case the string value of the value being checked is null.
Use String class's equals() method to compare Strings. The following links would give you more details.
About equals(Object yourObj) method (CASE sensitive)
equalsIgnoreCase(String yourStringObject) can be used, if you want it to be not case sensitive!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With