mercredi 6 octobre 2021

How to implement a validation in my activity with a checkbox?

How can I validate my checkbox, I have an editTex with the following message "To add your data you need to accept the terms and conditions", I want to be displayed when the user wants to try to add or perform any other action with other elements before checking the terms and conditions.

This is my mockup of my activity where I want to put validation

It does not let me put an image of my screen but I have as first element a checkbox(terms and conditions), then I have three textview (name, last name, age) and three edittext (name, last name, years) and a next button.

I have the following function but it does not work

public void validationCheck() {
    check = findViewById(R.id.checkBox);
    check.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean isCheked) {
            if (!isCheked) {
                editText.setEnabled(false);
                editText.setFocusable(false);
                editText.setFocusableInTouchMode(false);
                tvErrorValidacion.setText(getResources().getString(R.string.error_not_check));
            } else {
                editText.setEnabled(true);
                editText.setFocusable(true);
            }
        }
    });
}



Aucun commentaire:

Enregistrer un commentaire