setOnClickListener - How to Create a Click Handler for a Button, using a method

setOnClickListener was added in API Level 1
Register a callback to be invoked when this view is clicked. If this view is not clickable, it becomes clickable.
Parameters: the callback that will run

1. In the MainActivity.java file, add a new method called myButtonClickListener.

2. In the imports section, add the below imports.

import android.view.View.OnClickListener;
import android.view.View;

3. In the new method myButtonClickListener:

    a. Find a button using ID and name it myButton.

    b. Next add the below code to the myButtonClickListener method.

myButton.setOnClickListener(new View.OnClickListener() {
    @Override

    public void onClick(View v) {
        //add toast here for testing if you like.
    }
});

4. Add the new method to the onCreate method to initialize.

myButtonClickListener();

5. Compile and run!

Resources:
http://developer.android.com/reference/android/widget/Button.html
http://developer.android.com/reference/android/view/View.html#setOnClickListener(android.view.View.OnClickListener)