2
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。但我也无法比较两个值

4

2 回答 2

1

像这样比较

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");
       }
    }
});
于 2013-06-13T08:29:57.330 回答
0

尝试if(value.toString().trim().equalsIgnoreCase(regsCode1))

于 2013-06-13T08:31:53.470 回答