glomadrian / material-animated-switch

A material Switch with icon animations and color transitions
1.18k stars 158 forks source link

How to read the state of the switch? #3

Closed RoqueCampos closed 9 years ago

RoqueCampos commented 9 years ago

Hi! Your material design switch is cool!

But, how to read the state of the switch? I know that I receive the boolean flag in my onchangestatelistener but not the id of the view that did launched the event. Because of that I try to determine the state of each view, but I don't find the method to read the state.


Como creo que eres español, te lo comento en español ya que mi ingles no es muy bueno. El componente me parece genial, esta diseñado con mucho gusto, pero no encuentro como leer el estado del switch. ¿Hay algun metodo tipo isChecked o algo asi?

Un saludo y gracias.

mcguile commented 9 years ago

switch.setOnCheckedChangedListener (new MaterialAnimatedSwitch.OnCheckedChangeListener() { @Override public void onCheckedChanged(boolean b) { if (b) { // switch is set to right } else { // switch is set to left }}});

RoqueCampos commented 9 years ago

Yes, I know that way, but what if you have a lot of checkboxes? One listener per checkbox? Thats look not very optimized.

What I want is to register the interface in my activity, and when the event is triggered, I prefer to look the state of all of the checkboxes using reflection... but no method is available to read the status of the checkbox.

glomadrian commented 9 years ago

Hi, the new version of the library have a isChecked() method like @RoqueCampos says