I have a certain situation where we see that it is possible to create in the XML file a property called onClick
:
onClick:
XML:
<Button
android:layout_height="@dimen/edittext_min_height"
android:layout_alignParentLeft="true"
android:minWidth="120sp"
android:onClick="btnSend"
android:clickable="true"/>
Class:
public void btnSend(View view){
//faça algo
}
On the other hand we can also instantiate within the class the setOnClickListener()
:
setOnClickListener:
XML
<Button
android:id="@+id/btnSend"
android:layout_height="@dimen/edittext_min_height"
android:layout_alignParentLeft="true"
android:minWidth="120sp"/>
Class:
Button btnSend = (Button) findViewById(R.id.btnSend);
btnSend .setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//faça algo
}
});
What would be the advantages and disadvantages between using onClick
and setOnClickListener
?