‫Welcome back.
‫In this video, we'll handle the click events on the other buttons.
‫But wait, if I need to create for every button set on click listener and then media player and started,
‫this will make our code a boilerplate code and a lot of duplication.
‫And this is not a professional way where you can deal with multiple buttons.
‫We need to make a professional way, a simple trick that will handle the button.
‫Click with no boilerplate code for that.
‫The first step is to implement here the view dot on Click Listener interface View dot on Click Listener
‫interface is an interface that provides a way to handle click events on UI elements, especially instances
‫of the view class.
‫It's commonly used to define and manage the behavior that should occur when a user clicks or interacts
‫with a particular UI element such as the button.
‫In our case, the view on Click listener interface has a single method.
‫If we click on control and go to the on Click listener interface, we can see that this interface has
‫only one method which is on click.
‫When you implement this interface and override the on click method, you define the action that should
‫be taken when the associated view is clicked, the view parameter represents the view that was clicked.
‫Click alt plus enter to implement the methods and which is the only method in this case which is the
‫on click.
‫You can see that the on click is Overrided outside the Oncreate method.
‫And this is similar to this because here I passed as an anonymous instance of this interface.
‫I remove this red button, click listener and I need to associate these buttons with the interface.
‫So red button dot set on click listener and I'll pass this.
‫This refers to this view on click listener interface.
‫Here we're adding this keyword to the on click listener method.
‫It redirects the call to the on click method that it is implemented and override it here.
‫If you don't use this keyword here, your call will not be redirected to the on click method.
‫Again, I'll add for the other buttons.