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 は両方の値を正しく出力しますが、2 つの文字列を比較しないため、Editable 値を String 値から変更し、オブジェクト クラスの toString fn を使用しました。しかし、2つの値を比較することもできません

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 に答える