I wonder how Android provides several ways to implement its button click method. At least I found 2 ways, first is using command listener on Java code, second is using android:onClick ="method" in xml and public void method(View v) in java. So my question is, which one is the best in case of simplicity and effectiveness in programming. Thanks.
I wonder how Android provides several ways to implement its button click method. At
Share
I heard that often defining the onClick within xml can lead to problems with proguard. 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
// Just to add for those wanting to use OnClick within xml and proguard
Add this:
However the more obfuscation the merrier in my humble opinion 😛