java - Two ways of assigning a button's onclick method -


this question has answer here:

i'm watching/reading tutorials these days android app development. , i've learnt 2 different ways of assigning button's onclick method. 1 declare in xml:

<button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button_send" android:onclick="sendmessage" /> 

the other finding id button:

button mybtn = (button) findviewbyid(r.id.button1); mybtn.setonclicklistener(new view.onclicklistener() {      @override     public void onclick(view v) {         //do something...                } }); 

my question is: what's difference (advantage , disadvantage) of each method, , if efficiency different, 1 faster other it's preferred?

the efficiency difference not going matter because small, guess xml method faster since avoids object creation.

however, assumes overhead whatever linking done through xml smaller object creation overhead.

my advice: don't worry small efficiency advantages in cases executed few times.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -