The system calls the onCheckedChanged()
method for you and passes the arguments to the method whenever the check state changes for the CheckBox you have added the listener to. This is automatically handled by the system with the correct arguments (the CheckBox
whose check state has changed and whether it is now checked or not) and you probably will never want to call onCheckedChanged()
manually in your code.
You should be aware that you are not subscribing the method onCheckedChanged()
directly to the event. You are actually creating an anonymous class that implements the onCheckedChangeListner
interface and implementing that method in this class. You are passing in an instantiated object of this class to the setOnCheckedChangeListener()
method.
Notice the onCreate()
method that you are overriding in the code you posted. This is similar in that it is called by the system when creating an Activity
object. Nowhere in your own code will you call onCreate()
on an Activity
object, it is a callback for you to override and add your code to.