I'm watching/reading some tutorials these days about Android app development. And I've learnt two different ways of assigning a button's onclick method. One is to declare it in XML:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="sendMessage" />
The other is by finding the id the 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 the difference (advantage and disadvantage) of each method, and if the efficiency is different, one is faster than other so it's usually preferred?