我想检查一个字符串值,但如果它总是输入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();
}
请不要使用==来比较字符串。请不要。 – Maroun
使用equals()函数 –
对于那些回答,您可能还想给出一个解释.....特别是当这个问题已被回答1000次。 – Maroun