2016-02-29 66 views
0
........................................ 
else if (e8.getText().toString().length() == 0) { 
        e8.setError("Password is required"); 
        Toast.makeText(getApplicationContext(), "Please enter Password", Toast.LENGTH_SHORT).show(); 
        i = 0; 

       } 

       else if (e9.getText().toString().length() == 0) { 
        e9.setError("Password is required"); 
        Toast.makeText(getApplicationContext(), "Please enter Password", Toast.LENGTH_SHORT).show(); 
        j = 0; 
       } 

       else if (!e8.equals(e9.getText())) 
       { 
        e9.setError("Both Passwordsxmvbxb are different"); 
        Toast.makeText(getApplicationContext(), "Please enter Correct Password", Toast.LENGTH_SHORT).show(); 
        k = 0; 
       } 
........................................ 
+2

的可能的複製[機器人:Validatng密碼,密碼相符並傳遞一個字符串值通過按鈕](http://stackoverflow.com/questions/6409118/android- validatng-密碼符合密碼和傳遞-一個字符串值,通過量) –

回答

0

當您檢查任意兩個字符串時,它應該是字符串。目前你在做e8.equal其中e8是你的EditText所以它會檢查相同的對象。它應該是

if(!e8.getText().toString().equals(e9.getText().toString())) 
0

使用.equals代替==比較字符串。

1

嘗試這個

} 

     else if (e9.getText().toString().equals("")) { 
      e9.setError("Password is required"); 
      Toast.makeText(getApplicationContext(), "Please enter Password", Toast.LENGTH_SHORT).show(); 
      j = 0; 
     } 

     else if (!e8.getText().toString().equals(e9.getText().toString())) 
     { 
      e9.setError("Both Passwordsxmvbxb are different"); 
      Toast.makeText(getApplicationContext(), "Please enter Correct Password", Toast.LENGTH_SHORT).show(); 
      k = 0; 
     } 
1

嘗試這種方法。

if(validate()){ 
    // perform operation 
} 

方法聲明:

private boolean validate() 
    { 
    if (TextUtils.isEmpty(edtPassword.getText())) { 

     //toast enter password 

     return false; 

    } else if (TextUtils.isEmpty(edtConfirmPassword.getText())) { 

     //toast enter confirm password 

     return false; 
    } else if (!edtPassword.getText().toString().equals(edtConfirmPassword.getText().toString())) { 
     //toast password not match 

     return false; 
    } 
    return true; // considering all conditions are true 
}