There are two types of buttons in the Android SDK: regular buttons and toggle buttons. We could do without toggle buttons but it would require more programming than necessary. In this tutorial you will learn to check the state of a toggle button.
the toggle button with a message displaying its state
Making The Toggle Button
The toggle button requires the use of the ToggleButton tag. Let’s make a button that is centered on the screen, the button will call a function called toggle() on click.
You can also change the on and off text of the button by adding the following attributes to the ToggleButton tag:
Handling The Clicks
app behavior when the button is toggled on, a similar effect takes place when it's toggled off
All we need to do is check the isChecked() method of the toggle button object inside our toggle() function. The following code does the checking and also raises a toast with the state of the button.