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. Find a button using ID and name it myButton.
2. In the imports section, add the below imports.
import android.view.View.OnClickListener;
import android.view.View;
myButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//add toast here for testing if you like.
}
});
4. Compile and run!
Next Recommended Article: setOnClickListener - Create a Click Handler for a Button, using a method
Resources:
http://developer.android.com/reference/android/widget/Button.html
http://developer.android.com/reference/android/view/View.html#setOnClickListener(android.view.View.OnClickListener)