早上好,我的问题是在DialogAlert中if else,当我输入四个相等的数字时,它没有做出正确的函数,这会比较pass1和pass2,但它会PIN的功能是不同的。为什么它不比较pass1和pass2?
非常感谢。
loginbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String valor1 = pass1.getText().toString();
String valor2 = pass2.getText().toString();
if ((pass1.getText().toString().length() < 4) || pass2.getText().toString().length() < 4)) {
Toast.makeText(getApplicationContext(), "Enter 4 digits and the same pin", Toast.LENGTH_SHORT).show();
pass1.setText("");
pass1.requestFocus();
pass2.setText("");
} else if (pass1.equals(pass2)) {
Toast.makeText(getApplicationContext(), "Account create", Toast.LENGTH_SHORT).show();
alertDialog.dismiss();
} else {
pass1.setText("");
pass1.requestFocus();
pass2.setText("");
Toast.makeText(getApplicationContext(), "The pin is different, makes the same pin", Toast.LENGTH_SHORT).show();
}
}
});
答案 0 :(得分:2)
而不是比较控件:
} else if (pass1.equals(pass2))
您应该比较控件中包含的字符串:
} else if (pass1.getText().toString().equals(pass2.getText().toString()))