当我第一次按下signUpBinding.finishSignUp.setOnClickListener()时,它不会导航到仪表板片段,但是当我第二次尝试输入有效的用户名时,它将立即执行导航,从而跳过电子邮件和其他验证的其余部分。密码。
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
navController = Navigation.findNavController(view);
signUpBinding.setAuthViewModelBinder(authViewModel);
signUpBinding.finishSignUp.setOnClickListener(v -> {
username=signUpBinding.username.getText().toString();
email=signUpBinding.username.getText().toString();
password=signUpBinding.username.getText().toString();
phonenumber=signUpBinding.username.getText().toString();
if(username.length()<5)
{
Toast.makeText(getActivity(), "Username need to be longer", Toast.LENGTH_SHORT).show();
return;
}
if(email.length()<5)
{
Toast.makeText(getActivity(),"Email need to be longer",Toast.LENGTH_LONG).show();
return;
//
}
if(password.length()<5)
{
Toast.makeText(getActivity(), "Password need to be longer", Toast.LENGTH_SHORT).show();
return;
}
User user=new User();
user.setEmail(email);
user.setPassword(password);
user.setUsername(username);
user.setPhone(phonenumber);
authViewModel.CreateUserWithEmailAndPassword(user).observe(getViewLifecycleOwner(), s -> {
Toast.makeText(getActivity(), s, Toast.LENGTH_SHORT).show();
navController.navigate(SignUpFragmentDirections.actionSignUpFragmentToDashboardFragment());
});
});
}