I have tried the code in the answer of android-widget-switch-on-off-event-listener, but the post doesn't say anything about the error I got trying to use it.
At the second line of the suggested code:
switch1 = (Switch) findViewById(R.id.switch1);
switch1.setOnCheckedChangeListener(new OnCheckedChangedListener() { //This line has the error
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
aTextView.setText("Switch was toggled");
}
});
This error triggers
The method setOnCheckedChangeListener(CompoundButton.OnCheckedChangeListener) in the type CompoundButton is not applicable for the arguments (new OnCheckedChangedListener(){})
How can I fix this? All I want to do is call a function when the switch changes - as opposed to when it is clicked. Thanks.