OnClickListener for Multiple Buttons – Android Studio Tutorial


In this video we will learn, how to set OnClickListeners for multiple buttons and handle them all in one onClick method. Instead of passing an anonymous inner class to the setOnClickListener method, we will pass the activity itself and implement the OnClickListener interface into our MainActivity. We will then use a switch/case statement to check for the button IDs and handle the corresponding button click.

Source code:

❗ Subscribe to the channel:

⏯ Watch more tutorials:

⭐ Become a channel member for exclusive tutorials and other perks:

㊙ Help translating the videos:

? Support the content:

? Join the Discord chat:

? Audiobooks and podcasts for programmers:

? How to get started with Android development:

? Follow Coding in Flow on social media:







  1. Bro you're the best. You are one of my favorite channel when it comes to Android Studio tutorial. KEEP IT UP bro. Godbless always 🙂

  2. Sir, This is good video but I have a question that how we can add webview in these buttons and webview should be open in one fragment.

  3. Hi Sir,

    They call what you have done in this video Register Events Listener. Would you please explain what is this registration they talk about?


  4. Hallo, danke für das Video. Kann man mehreren Buttons auch eine Methode zuweisen?
    Z.B. if ((view.getId() == R.id.button1 || (view.getId() == R.id.button2) || (view.getId() == R.id.button3))
    Ansonsten müsste man ja 3 if-Blöcke erstellen, die ein und die gleiche Methode beinhalten.

  5. Thank you for this tutorial. Could you also make a video where three buttons (play, pause, stop) but for many (8 or 10) tracks are shown on a second activity page. You have both in separate videos; I seem to have a problem combining the two. Best.

  6. This is super cool. Came very handy when I was looking for an explanation behind this inner class concept. Thank you so much for the tutorial.


Please enter your comment!
Please enter your name here