gpt4 book ai didi

java - 无法检查字符串值

转载 作者:搜寻专家 更新时间:2023-11-01 08:02:21 26 4
gpt4 key购买 nike

我正在尝试检查 if 中的字符串值,但它总是输入 else,这里有什么问题?谢谢

public void alertBtn(View v){
EditText text = (EditText)findViewById(R.id.editText1);
String value = text.getText().toString();
String password="asd";
if (value==password){

new AlertDialog.Builder(this)
.setTitle("Success")
.setMessage("Correct Password")
.setNeutralButton("OK", null)
.show();
}
else
new AlertDialog.Builder(this)
.setTitle("Error")
.setMessage("Wrong password")
.setNeutralButton("OK", null)
.show();



}

最佳答案

使用 == 运算符将比较对字符串的引用而不是字符串本身。

String value = text.getText().toString();
String password="asd";

if (value.equals(password))
{
}

关于java - 无法检查字符串值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19343369/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com