I know this seems like a duplicate question, but i was really unable to find a good answer on the related topic.

There are tons of questions about what is the best way to handle an OnClick event of a Button.
Here are some of the options i came across:

1 - Defining a listener programatically on the OnCreate method:

button.setOnClickListener(new OnClickListener(){
    @Override
    public void onClick(View v) {
        //do stuff
    }
});

2 - Setting the android:OnClick property on the XML:

<Button android:id="@+id/btnDelete"
    ...
    android:OnClick="btnDelete_OnClick"/>

3 - Implementing the OnClickListener interface on the Activity class and passing a self reference to the Button:

public class MainActivity extends Activity implements OnClickListener{
    @Override
    public void onClick(View v) {
        //do stuff
    }

    protected void onCreate(Bundle savedInstanceState) {
        ...
        button.setOnClickListener(this);
    }
}

4 - Create a field with the OnClickListener type:

private OnClickListener onClickHandler = new OnClickListener(){

    @Override
    public void onClick(View v) {
        //stuff
    }
};

protected void onCreate(Bundle savedInstanceState) {
    ...
    button.setOnClickListener(onClickHandler);
}

When it comes to a Button and the OnClick event, I would always prefer defining it on the XML, it is just more clean.

But what about other events like the OnItemClick from the ListView or the OnTimeSet from the TimePickerDialog? There is no property I can see for setting it on the XML. I think that implementing the Listener interface is a pretty clean solution, but th

Edit
Report