1mySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
2 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
3 // do something, the isChecked will be
4 // true if the switch is in the On position
5 }
6});