Niv
Niv

Reputation: 2312

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?

Upvotes: 3

Views: 9909

Answers (3)

Austyn Mahoney
Austyn Mahoney

Reputation: 11408

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.

Upvotes: 4

RajaReddy PolamReddy
RajaReddy PolamReddy

Reputation: 22493

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.

Upvotes: 3

sandrstar
sandrstar

Reputation: 12643

The difference become clear from the documentation:

public boolean isActivated ()

is View method and responsible for providing basic View state. Here is clear description of what activation is in Android terms.

From the other hand,

public boolean isChecked ()

is more 'high level' property of another entity - CompoundButton and provides it's state - is it ON or OFF.

Upvotes: 2

Related Questions