Adding Code To A Button Click In Android Studio
To define the click event handler for a button, add the android onClick attribute to the Button element in your XML layout. The value for this attribute must be the name of the method you want to call in response to a click event. The Activity hosting the layout must then implement the corresponding method.