java无法比较警报对话框“编辑文本”和“我的字符串”中的值
regsCode1=objCommonServices.fetchRegisterationCode(etMobileNo.getText().toString().trim(),etPassword.getText().toString().trim());
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Recharhge Confirmation");
alert.setMessage("Message");
// Set an EditText view to get user input
final EditText input = new EditText(this);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Editable value = input.getText();
System.out.println("Hello"+regsCode1 +" Value is "+value.toString());
if(value.toString().equals(regsCode1)){
System.out.println("Hello"+regsCode1+" "+value);
}
else{
System.out.println("B");
}
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
}
});
alert.show();
我得到的结果是B。因为系统。正确打印两个值,但不比较两个字符串 我甚至将可编辑值从字符串值更改为对象类的字符串fn。但我也不能比较两个值
# 1 楼答案
试试
if(value.toString().trim().equalsIgnoreCase(regsCode1))
# 2 楼答案
这样比较