When we create a button in layout, we can use the android:onClick
attribute to reference a method in code to handle clicks.
Button
<Button
android:width="120dp"
android:height="wrap_content"
android:text="Click me"
android:onClick="handleClick" />
Then in your activity, create the handleClick
method.
public void handleClick(View v) {
// Do whatever.
}