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:
Facebook:
Instagram:
Twitter:
Blog:
Nguồn:https://wijstaanvooronzegrondrechten.org/
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 🙂
Great The best Explain i have found Ever thanks
Congratulations on 1 lakh subscribers
Thank you! for sharing
Thanks, exactly that I needed!!!
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.
How can i make a single button which work for multiple things atleast for two things
thankyou very much
Love this tutorial. How do we modify the code, so that it also plays an audio clip when the button is clicked?
Thanks a lot !!!
Thanks a lot!
so helpful. I am just learning
thant you , i'm using a for loop in my case , is that good ?
thankyou so much it was very helpfull
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?
Thanks
This button can open new activity or not
Sorry, is it possible to use this method but within a Dialog or BottomSheetDialog with multiple buttons?
Very short and useful tutorial. Thank you 😉
I need to do it in kotlin, please help me
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.
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.
Thanks! Do you have a tutorial that shows how to make the buttons open an activity?
just like we say thanks in Kurdish (سوپاس)
How do you do Button.OnClickListener
Hey, man! Just wanna say thanks a lot for this! Really helped me in the project I was doing :3
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.
Thanks a lot man! your tutorials really help!