[JAVA] [Kotlin / Android] Listener rewrite
main.java
//Get Switch with id switchButton
Switch switchButton = (Switch) findViewById(R.id.switchButton);
//Set the processing when the switchButton is switched on and off
switchButton.setOnCheckedChangeListener(
new CompoundButton.OnCheckedChangeListener(){
public void onCheckedChanged(CompoundButton comButton, boolean isChecked){
//If on
if(isChecked){
}
//If off
else{
}
}
}
);
}
main.kt
switch.setOnCheckedChangeListener { _, isChecked ->
if (isChecked) {
//ON processing
} else {
//OFF processing
}
}
-Reference site