I'm creating a Android
application which uses a Switch.
I'm trying to listen for changes and get the value when changed.
I have two questions when using switches:
- What
action listener
do I use? - How do I get the the
switch
value?
I'm creating a Android
application which uses a Switch.
I'm trying to listen for changes and get the value when changed.
I have two questions when using switches:
action listener
do I use?switch
value?
Since it extends from
CompoundButton
(docs), you can usesetOnCheckedChangeListener()
to listen for changes; useisChecked()
to get the current state of the button.Hint:
isChecked
is the new switch value [true
orfalse
] not the old one.i hope this will solve your problem