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();
Resources:
http://developer.android.com/reference/android/widget/Button.html
http://developer.android.com/reference/android/view/View.html#setOnClickListener(android.view.View.OnClickListener)