I use an EditText
with android:password="true"
to let the user type the password. Then I want to compare the password with a hard coded password when the user presses a button.
But I can't compare the password with a String "mypassword". Here is the code I use to check the password:
EditText pw = (EditText) findViewById(R.id.pwdTxt);
if(pw.getText().equals("mypassword")) {
Intent i = new Intent(LoginActivity.this, LinkpageActivity.class);
startActivity(i);
} else {
// Wrong password
}
The comparison pw.getText().equals("mypassword")
returns false
even if I type the correct password. How should I check the password fro开发者_Python百科m an EditText
?
Maybe you could try
pw.getText().toString().equals("mypassword")
精彩评论