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。因为 System.out 正确地打印了两个值,但它没有比较两个字符串 我什至从 String 值更改了 Editable 值,并使用了对象类的 toString fn。但我也无法比较两个值
最佳答案
这样比较
public void onClick(DialogInterface dialog, int whichButton) {
String value = input.getText().toString().trim(); /// use this line
System.out.println("Hello"+regsCode1 +" Value is "+value);
if(value.equals(regsCode1)){
System.out.println("Hello"+regsCode1+" "+value);
}
else{
System.out.println("B");
}
}
});
关于java - 无法比较警报对话框编辑文本和我的字符串中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17082511/