gpt4 book ai didi

java - 我的验证全部合一

转载 作者:行者123 更新时间:2023-12-02 10:56:33 24 4
gpt4 key购买 nike

我在验证时遇到一些问题。如何更改我的编码,以便一次进行一个验证。我看了很多教程,这里是结果。我希望我的验证能够一一得到。那么应该如何呢?提前致谢。

  private void RegisterAccount(String firstname, String lastname, String email, String password, String confirmpass)
{
if (TextUtils.isEmpty(firstname))
{
Toast.makeText(Signup.this, "Enter your first name.", Toast.LENGTH_LONG).show();
}

if (TextUtils.isEmpty(lastname))
{
Toast.makeText(Signup.this, "Enter your last name.", Toast.LENGTH_LONG).show();
}

if (TextUtils.isEmpty(email))
{
Toast.makeText(Signup.this, "Enter your valid email address.", Toast.LENGTH_LONG).show();
}

if (TextUtils.isEmpty(password))
{
Toast.makeText(Signup.this, "Enter your password.", Toast.LENGTH_LONG).show();
}

if (TextUtils.isEmpty(confirmpass)) {
Toast.makeText(Signup.this, "Please write your password again.", Toast.LENGTH_LONG).show();
}

if (password != confirmpass)
{
Toast.makeText(Signup.this, "Password do not match", Toast.LENGTH_LONG).show();
}

else
{
loadingBar.setTitle("Creating New Account");
loadingBar.setMessage("Please wait while we are creating account for you.");
loadingBar.show();

mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>()
{
@Override
public void onComplete(@NonNull Task<AuthResult> task)
{
if(task.isSuccessful())
{
Toast.makeText(Signup.this, "You have successfully signed up", Toast.LENGTH_SHORT).show();
Intent mainIntent = new Intent(Signup.this, MainActivity.class);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(mainIntent);
finish();
}
else
{
Toast.makeText(Signup.this, "Error occured, please try again.", Toast.LENGTH_SHORT).show();
}
loadingBar.dismiss();
}
});
}
}
}

最佳答案

您应该使用 else -if 而不是 if。

if (TextUtils.isEmpty(firstname))
{
Toast.makeText(Signup.this, "Enter your first name.", Toast.LENGTH_LONG).show();
} else if (TextUtils.isEmpty(lastname))
{
Toast.makeText(Signup.this, "Enter your last name.", Toast.LENGTH_LONG).show();
} else if (TextUtils.isEmpty(email))
{
Toast.makeText(Signup.this, "Enter your valid email address.", Toast.LENGTH_LONG).show();
}else if (TextUtils.isEmpty(password))
{
Toast.makeText(Signup.this, "Enter your password.", Toast.LENGTH_LONG).show();
} else if (TextUtils.isEmpty(confirmpass)) {
Toast.makeText(Signup.this, "Please write your password again.", Toast.LENGTH_LONG).show();
}else if (password != confirmpass)
{
Toast.makeText(Signup.this, "Password do not match", Toast.LENGTH_LONG).show();
}

关于java - 我的验证全部合一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51691350/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com