Which is better way performance wise , andriod:onClick or set onClickListener for android objects

Android docs mention two ways to set an onclick event on a button :
1.Using the android:onClick XML attribute where you just use the name of a public method with the signaturevoid name(View v) 
2. By using the setOnClickListener method where you pass an object that implement the OnClickListener interface. 

Which one is  correct ways ? Which is better techniques performance wise?

Please Expalin why
Last updated:7/22/2015 8:09:27 AM

1 Answers

Mayank Tripathi
Mayank Tripathi

I think performance wise there is not much difference in both the approaches,The xml approach , android: onClick is provided to maintain clean coding in our activity.

But if  we define the code implementation in xml's on click method   we need to make the method always as public, i.e. we are exposing our implementation unnecessarily  which is not a good pratice, so my personal fav is the other way,  i prefer setOnclickListener way over the xml approch. This way we can make the implementation private.