lundi 17 août 2020

How to validate CheckBox alongside my current signing up code? - Android Studio

I currently have the following code below which ensures that a user is aware they need to add username and password correctly before logging in. Today i added a Terms and Conditions and a privacy policy to the sign up page through using 'CheckBox'.

I was wondering if someone could show me how to make the code below also make sure that the user checks the boxes to state they agree and have read the agreements and then they are able to sign in.

Thanks. Feel free to ask questions if you are confused by my wording. Appreciate your time in advance.

        @Override
        public void onClick(View v) {
            String email = emailid.getEditText().getText().toString().trim();
            String pwd = password.getEditText().getText().toString().trim();
            if(email.isEmpty()) {
                emailid.setError("Please enter email");
                emailid.requestFocus();
            }
            else if(pwd.isEmpty()) {
                password.setError("Please enter a password");
                password.requestFocus();
            }
            else if(email.isEmpty() && pwd.isEmpty()) {
                Toast.makeText(signup.this,"Fields are Empty!",Toast.LENGTH_SHORT).show();
            }

            else if(!(email.isEmpty() && pwd.isEmpty())) {
                mFirebaseAuth.createUserWithEmailAndPassword(email, pwd).addOnCompleteListener(signup.this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {

                        if(!task.isSuccessful()){
                            Toast.makeText(signup.this,"SignUp Unsuccessful, Please Try Again",Toast.LENGTH_SHORT).show();
                        }
                        else {
                                    startActivity(new Intent(signup.this, homescreen.class));
                        }
                    }
                });
            }
            else{
                Toast.makeText(signup.this,"Error Occurred!",Toast.LENGTH_SHORT).show();

            }
        }
    });



Aucun commentaire:

Enregistrer un commentaire