Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ToggleButton isChecked vs isActivated - Android

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?

like image 640
Niv Avatar asked Dec 12 '25 17:12

Niv


2 Answers

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.

like image 163
Austyn Mahoney Avatar answered Dec 14 '25 06:12

Austyn Mahoney


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.

like image 45
RajaReddy PolamReddy Avatar answered Dec 14 '25 07:12

RajaReddy PolamReddy