在android中,无法在密码和重复密码之间进行检查

在android中,无法在密码和重复密码之间进行检查,android,Android,当您检查任意两个字符串时,它应该是字符串。当前您正在执行e8.equal,其中e8是您的编辑文本,因此它将检查equal对象。应该是 ........................................ else if (e8.getText().toString().length() == 0) { e8.setError("Password is required"); Toast.makeText

当您检查任意两个字符串时,它应该是字符串。当前您正在执行e8.equal,其中e8是您的编辑文本,因此它将检查equal对象。应该是

........................................
 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;
                }
........................................
使用.equals而不是==来比较字符串。

试试这个

试试这种方法

}

        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;
        }
方法声明:

if(validate()){
    // perform operation
}
可能重复的
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
}