On the Internet, I encountered two interesting constructions, and although I use only the first, I still took an interest up, which one is better to use in my projects? I admit that the question is banal, but I cannot ask;) So, the first construction:
private OnClickListener myListener = new OnClickListener() { public void onClick(View v) { // do something when the button is clicked } }; protected void onCreate(Bundle savedValues) { ... // Capture our button from layout Button button = (Button)findViewById(R.id.close); // Register the onClick listener with the implementation above button.setOnClickListener(myListener); ... } And the second no less interesting design:
<Button android:layout_height="wrap_content" android:id="@+id/butHello" android:layout_width="wrap_content" android:text="Поздороваться" android:onClick="butHello_Click" /> Here we have defined the onClick event. < Is it considered to be generally from the " Best Practice " range?
After which they registered the method (to our .xml):
public void butHello_Click(View v){ edtext.setText("Здравствуй, друг"); }