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

Change php variable from jquery value using ajax (same page) -

How can I fetch data from a web server in an android application? -

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