I'm trying to see what method of the ToggleButton widget is used to check if it is switched to "on" or "off", and I couldn't make out of the reference if it's isChecked() or isActivated()
What are the differences between the two?
View.setActivated() says in the JavaDoc that the activated state has nothing to do with CheckBox or ToggleButton, but with some kind of selection state that a generic View can be in when in a ListView.
The developers even apologize for the confusion:
Um, yeah, we are deeply sorry about the terminology here
isActivated() is also only available on API levels > 11.
isChecked() is from CompoundView, which ToggleButton and CheckBox both extend from. This is the state that you want to be checking for. It is available on all API levels.
use isChecked() for ON and OFF
if (isChecked()) {
// The toggle is enabled ON state
} else {
// The toggle is disabled OFF state
}
As i know there is no isActivated() method for toggle button, it is for a view either it is active or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With