qwertz
qwertz

Reputation: 6286

Android switch off SwitchPreference programmatically

Is there a way to switch off a SwitchPreference programmatically? I tried using setEnabled(false) but that just disables the SwitchPreference, but the switch stays in the on position.

Is there a method to disable the switch programmatically so it goes back to the off position?

Upvotes: 0

Views: 2920

Answers (1)

seanAshmore
seanAshmore

Reputation: 315

setEnabled as you say is to enable/disable the actual switch.

To turn it on/off programmatically try setChecked(true) / setChecked(false): http://developer.android.com/reference/android/preference/TwoStatePreference.html#setChecked(boolean)

Upvotes: 4

Related Questions