In the Android API Guides for checkboxes , they state that you can set the attribute in XML format ( android:onClick ) to run the assigned method. The same thing is said in the button manual , but the button manual also has this bit:
You can also declare a click event handler pragmatically, rather than in an XML layout. This may be required if you create an instance of Button at runtime or you need to declare click behavior in a subclass of Fragment .
The following question arises: can you or can not use the android:onClick attribute if the button or checkbox is in the Fragment? If so, I would suggest that the method that will be called will be declared in the Fragment, right?
source share