Exploring the palette and more anonymous classes – part 2
Now that we have seen how anonymous classes work, specifically with RadioGroup and RadioButton, we can continue to explore the palette and examine 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 widget, except it has two possible states that can be read and responded to.
One obvious use for the Switch widget is to show or hide something. Remember that in our Java Meet UI app, in Chapter 12, The Stack, the Heap, and the Garbage Collector, we used a Button widget to show and hide a TextView widget.
Each time we hid or showed the TextView widget, we changed the text property on the Button widget to make it clear what would happen if it was clicked on again. What might have been more intuitive for the user, and more straightforward for us as programmers, would have been to use a Switch widget, as...