开发者

How to check the password from an EditView?

开发者 https://www.devze.com 2023-01-27 07:24 出处:网络
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.

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")
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号