dimanche 18 juillet 2021

Checkbox activity on my Android Example shows error with multiple texts show/hide option

This may be a silly question, but I am struck halfway when I tried to create a simple app with a checkbox. When I use the checkbox to show and hide a single text, this works fine. But if it's for a second text, the app crashes. I wanted to hide one text and show another when the checkbox is clicked.

enter image description here

Here is the code

        if (isChecked) {
            txtHelloWorld.setVisibility(View.VISIBLE);
            txtHelloWorldChecked.setVisibility(View.INVISIBLE);

        } else {

            txtHelloWorld.setVisibility(View.INVISIBLE);
            txtHelloWorldChecked.setVisibility(View.VISIBLE);

        }
    }



Aucun commentaire:

Enregistrer un commentaire