I have just come across the android:onClick="myCrazyMethod" XML attribute, seems pretty clean and simple.
I was just wondering though if there is any difference in performance between this approach – declaring a simple method and creating an OnClickListener class?
Declaring it in the XML is ever so slightly slower but not by much. However defining the onClick within xml can lead to problems with proguard (unless you implement the code below). Personally I feel the easiest is using a switch and case within the onclicklistener, but if the method is a lot longer then it’s nice to give it it’s own method so to “hide” it away. If you however need common code to run after any button is pressed (for example a UI refresh) might be better to leave it to a switch and case or if/else. However, all of this is of course my opinion on the matter.
// Just to add for those wanting to use OnClick within xml and proguard
Add this: