Exploring the palette – Part 2, and more anonymous classes
Now that we have seen how anonymous classes work, specifically with RadioGroup and RadioButton, we can now continue exploring the palette and look at how anonymous classes work with some more UI widgets.
Switch
The Switch (not to be confused with the lowercase switch Java keyword) widget is just like a Button except that it has two possible states that can be read and responded to.
An obvious use for the Switch widget would be to show and hide something. Remember in our Java meet UI app in Chapter 12, The Stack, the Heap, and the Garbage Collector, that we used a Button to show and hide a TextView?
Each time we hid/showed the TextView, we changed the Text property on the Button to make it plain what would happen if it was clicked again. What might have been more logical for the user and more straightforward for us as programmers would have been to use a Switch, as illustrated here:

The following code assumes that we already...