Design + Code an Android App from Scratch
Scrounge up some loose change to become a pro member, or login to your account to view this lesson.
Alright, join now. Or login to your account if you're already a pro member.This video shows how to handle Button clicks in Android. There are 5 different ways for doing this. Use the android:onClick attribute in XML and give some method name as the value of this attribute. Define this method inside the Activity and ensure it takes a View argument. As an alternative you can let your Activity or Fragment implement the View.OnClickListener which is an interface with a single method called onClick. Set this listener on the Button by saying setOnClickListener. The other methods revolve around the different ways of doing this which would involve either implementing the Listener directly in the Activity or Fragment or using anonymous inner classes.