android.widget.Switch – on/off event listener?

I would like to implement a switch button, android.widget.Switch (available from API v.14).

<Switch
    android:id="@+id/switch1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Switch" />

But I’m not sure how to add an event listener for the button. Should it be an “onClick” listener? And how would I know if it is toggled “on” or not?

10 Answers
10

Leave a Comment