RecyclerView OnClickListener (Best practice way)

  Рет қаралды 291,468

CodingWithMitch

CodingWithMitch

5 жыл бұрын

This video is part of a course named "SQLIte for Beginners 2019". It's free and available on my website: codingwithmitch.com/courses/s...
In this video I show you the best practice way to attach an OnClickListener to a RecyclerView and determine what list item was clicked.
➤Learn to code like me:
↻ codingwithmitch.com/register/
➤Source Code:
↻ github.com/mitchtabian/SQLite...

Пікірлер: 374
@milkjpg
@milkjpg 5 жыл бұрын
i have a project due in 3 days and your channel is saving my life!! thank you so much for this!!! never clicked on subscribe this fast!!!
@jarrodthoma1866
@jarrodthoma1866 3 жыл бұрын
Mitch, I definitely appreciate your content. Software/firmware development is nothing new to me, but I recently got into app development, and this series has helped tremendously! I was having difficulty with changing the TextView text color within my ViewHolders in the RecyclerView, but was eventually able to figure it out with your interface examples on the Note RecyclerView series. Thank you so much.
@klekaelly
@klekaelly 2 жыл бұрын
Hey Mitch, just wanted to say I was stuck on a problem for a long time and your video (especially the part where you took us back and walked through everything we did) was super helpful. I was able to resolve my problem after re-approaching it with a clear head. Thanks for the guidance!
@Richie_
@Richie_ 4 жыл бұрын
Coding with Mitch & Coding in Flow are the 2 best tutors on KZbin.
@josepenasanchez1491
@josepenasanchez1491 4 жыл бұрын
Explaining what you code was doing as you typed, and at the end to summarized really helped!! Awesome tutorial!!
@kristians1550
@kristians1550 2 жыл бұрын
Had to come back to this video to say how much I appreciate what you do, I have used this in my recyclerView app a long time ago and now I was looking for a way to fix a similar issue in different java swing application where I used the same concept with an interface and it works as a charm. Man you really have no competition when it comes to this stuff. Wish you pleasant holidays mate, you deserve it
@joeypeters2916
@joeypeters2916 4 жыл бұрын
Mitch, I have a degree in mobile app development. I wish I would have seen this while in school. It helped a lot and will continue to help a bunch. Thank you for all you do.
@noodler911
@noodler911 3 жыл бұрын
5:36 the this keyword doesn't work for me. It provides ValueEventListener instead of OnNoteListener. Do you know how I can solve this problem?
@apartmentbluerose-trogir7869
@apartmentbluerose-trogir7869 4 жыл бұрын
God bless you Mitch! It works like a charm!
@moazelsawaf2000
@moazelsawaf2000 5 жыл бұрын
Thanks a lot ❤️ This method is called inter fragment communication and we use it when we want our fragment to communicate with the activity...
@huh_wtf
@huh_wtf 4 жыл бұрын
This was such a god sent....Thank you for uploading this. Such an elegant solution.
@GamerChris123
@GamerChris123 4 жыл бұрын
Finally helped me get my code up and running, migrating everything from Java to Kotlin was pretty seamless but the Adapter definitely gave me a couple migraines. Thanks!
@samusaran5509
@samusaran5509 5 жыл бұрын
Man i have been racking my brain trying to figure out why my click listener wasn't passing variables to a new activity. Thanks so much my dude.
@chloegeldhof4921
@chloegeldhof4921 5 жыл бұрын
Thank YOU!!!! I changed it a little to apply to a fragment but after hours of finding shite tutorials it's finally working! I'll put your name on my bachelors degree LOL
@wertin200
@wertin200 4 жыл бұрын
Did you find a way to Go from one fragment to Another fragment And then to show the id that was passed through
@ericsmith2405
@ericsmith2405 4 жыл бұрын
Just fantastic! Finally someone who can break down a myriad of core topics into a one simple brain folder!!
@codingwithmitch
@codingwithmitch 4 жыл бұрын
Haha "brain folder". I like that
@vladkondratiuk5886
@vladkondratiuk5886 5 жыл бұрын
That's great, dude! When I was finding on Russian chanels this info, I didn't do that, but when I saw your video, I understand that no metter what I need, I have to search everything on English chanels at ones!
@hugocc0318
@hugocc0318 Жыл бұрын
Omg I have learned more in this video than searching through a thousand forums, thank you very much
@ianrknowles
@ianrknowles 3 жыл бұрын
Tried to get a recyclerview click listener working for hours - this tutorial finally cracked it - Thank you!
@ki11qwerty47
@ki11qwerty47 4 жыл бұрын
omg!!! thanks a lot! i killed 1day to find best practice way for this )))
@sitibalqis8032
@sitibalqis8032 5 жыл бұрын
Thank you Mitch! I finally be able to go to another different activity for each item clicked! Implemented the switch case in the onNoteClick and it worked! :)))) p/s: I used the coding from your previous recyclerview and edited from there.
@sitibalqis8032
@sitibalqis8032 5 жыл бұрын
But only for the toast message, i don't know where to put the coding. But i guess it's okay as long as my goal is achieved 😂
@samha1513
@samha1513 5 жыл бұрын
Clear and to the point as always. Everytime I watch your video I learn something new. Thanks.
@dignitymashoko5437
@dignitymashoko5437 5 жыл бұрын
Man you are the best, keep up you are saving the world.
@WftYT
@WftYT 2 жыл бұрын
Thank you so much. I've got a huge project rn and the only thing that was troubling me is communication between the recycler view and the Activity that uses it. Thank you so much! It fixed my issue
@marcoantonioblancastokunag1864
@marcoantonioblancastokunag1864 2 жыл бұрын
I am very happy to find your content. Excellent explanation, I have signed up for the full course on your website. Thank you!
@codinginflow
@codinginflow 5 жыл бұрын
Wow you must be a programmer or something
@codingwithmitch
@codingwithmitch 5 жыл бұрын
😏
@goldwings1468
@goldwings1468 5 жыл бұрын
Coding in Flow approves 😃
@anhchung7340
@anhchung7340 5 жыл бұрын
funny :)
@ehtashamali821
@ehtashamali821 4 жыл бұрын
Ohh Glad to see you here. You both are Best. Please guide me on this issue. I try to resolve this issue from last two weeks but not getting solution yet. How can I change the View which is previously clicked in RecyclerView. I have a play button in every single row of RecyclerView. Whenever this button is clicked button visibility changed like shown in this image imgur.com/0fpk0Jv. When user click on first row button visibility changed which is working fine. But when user click on second row button of RecyclerView I want to change the button of first row to came back to its original position. Scenario shown in this image imgur.com/n4Q26Qm
@tarikbenaliamar4033
@tarikbenaliamar4033 4 жыл бұрын
Codingin Flow you too, you are a genius ;)
@matthewmirandaa
@matthewmirandaa 3 жыл бұрын
I know the video's a couple of years old but I just really need to say that this was a great video/explanation, thank you so much, helped out a lot, pura vida 🙌
@dungenhero7159
@dungenhero7159 3 жыл бұрын
I went to StackOverflow, couldn't find the solution. Then I found this. Worked like a charm. Thanks a lot
@themax734
@themax734 4 жыл бұрын
Thanks Mitch! This was exactly what I needed.
@martinsalcedoapps
@martinsalcedoapps 4 жыл бұрын
Really simple, great explanation. Thanks Mitch.
@nikhilcsuvarna8829
@nikhilcsuvarna8829 2 жыл бұрын
Thank you for this..I was searching whole day for this..🙌
@josephridge3646
@josephridge3646 3 жыл бұрын
Hey Mitch thank your for this !!! I appreciate the relay.
@user-dm1te2rj5u
@user-dm1te2rj5u 5 жыл бұрын
Thank you sooooooooo much for your super kind explanation!! I found it so easy to follow. I've actually tried several ways to apply OnClickListener to recycler items but I had failed to come here! I'll keep subscribing for additional help! >ㅁ
@sonuchristopherk2273
@sonuchristopherk2273 4 жыл бұрын
amazingly short and easy to understand.. Keep rocking!
@madhuthakur472
@madhuthakur472 5 жыл бұрын
Really appreciate the way you explain things .. made android easy for me ..
@john20johnny
@john20johnny 4 жыл бұрын
Hi, first I'd like to thank you for your videos and lessons, and then I got two questions that I hope you have time to answer. 1. How to make each item to open a new activity (not the same) example item (A) opens activity (A) and item (B) opens activity (B) and so on. 2. How to implement onBackPressed() or finish() method in the clickListener method of recyclerView, for example if item (A) clicked open activity (A) and finish its current activity. Thank you again.
@mikolajm9175
@mikolajm9175 3 жыл бұрын
This is gold among so much shitty stack answers i found. Much thanks for this explanation and BRILLIANT revision at the end.
@harisdurrani8422
@harisdurrani8422 3 жыл бұрын
Superb...i searched every where but all were directing to onBind Holder...and that was very confusing for me,,, but your method is very very easy...and it solved all my problem...love you for this helpful guide....
@red2fire2
@red2fire2 5 жыл бұрын
Cheers, This really helped
@mengmengliu6261
@mengmengliu6261 3 жыл бұрын
simple and elegant, thank you so much!
@pikachubolt2001
@pikachubolt2001 4 жыл бұрын
Thanks mitch, the other tutorial on another guy on how to setup a recyclerview had miss one thing on how to implement the listener to get clickevents, he forgot to add view.setonclicklistener(this); on the customviewholder. thanks again!
@BaldPL
@BaldPL 4 жыл бұрын
Thanks for help! Good quality example of create own listener and use it in RecyclerView.
@karagezify
@karagezify 4 жыл бұрын
Thanks for making this! Really helped me out!
@demoscena1180
@demoscena1180 5 жыл бұрын
Interesting. I was always using the "bad practice" way.
@darshans9186
@darshans9186 5 жыл бұрын
Oh shitt!! Have to make lots of changes in the code which I wrote today 😅 thanks alot mate. It's really helpful. Keep posting good stuff
@codingwithmitch
@codingwithmitch 5 жыл бұрын
I think next month I'm going to start posting shitty stuff
@switchend7776
@switchend7776 5 жыл бұрын
quality teaching bro thank you! learned a lot
@IbnBattuta2
@IbnBattuta2 5 жыл бұрын
Thanks. Great tutorial as usual.
@patrickgichuki1789
@patrickgichuki1789 4 жыл бұрын
Life and time saver! Thank you very much!
@ryujikomai8859
@ryujikomai8859 4 жыл бұрын
Super helpful and straightforward. Thanks so much :)
@Tronx431
@Tronx431 3 жыл бұрын
2021 ik but thx alot dude, you fixed my crahing issues. I have my holder class separated from my adapter class so every time I clicked one of my items it crashed but not anymore, ur the best.
@Kevin-HB
@Kevin-HB 3 жыл бұрын
Man, you help my life. THANK YOU SO MUCH!!!!!!
@CalvinJKu
@CalvinJKu 2 жыл бұрын
Thanks Mitch. I'm using a similar pattern but I'd like to 1. Add an overlay when an item in the RecyclerView is selected; 2. Change some UI in the hosting fragment when something inside the RecyclerView is selected. I find it quite difficult as the onClick methods and the UI is controlled by the fragment, while the item UI is controlled by the viewholder. Not sure how to get them to talk to each other.
@abdulazizfahim2140
@abdulazizfahim2140 3 жыл бұрын
Dude you are a LIFESAVER!!
@arunachalamk1145
@arunachalamk1145 5 жыл бұрын
keep doing bruh Great quality
@PenjinPinguino
@PenjinPinguino 4 жыл бұрын
Hi, great video! One question. In the adapter, when you add the click listener why is it needed to pass the OnNoteListener to the ViewHolder instead of using the one you have on the adapter directly? Is that bad practice? Can it cause problems?
@constanzacirion8100
@constanzacirion8100 3 жыл бұрын
this is exactly what i was looking for. thanks :)
@aleksandrbut9604
@aleksandrbut9604 5 жыл бұрын
thanks a lot, this is exactly what i was looking for
@Thatbigx
@Thatbigx 5 жыл бұрын
Thank you very much, helped a lot.
@vuphong2003
@vuphong2003 4 жыл бұрын
Clearly explained, plus you made it so easy. Thanks!
@javrz91
@javrz91 4 жыл бұрын
Excellent! This really helped a lot! Thanks!
@casenovo
@casenovo 3 жыл бұрын
Awesome Work Dude. Really Appreciate it.
@zadick2026
@zadick2026 5 жыл бұрын
Thank you so much bro it saves my time
@aslammamud6078
@aslammamud6078 3 жыл бұрын
Your tutorial helped me a lot. thanks. all the best.
@vahidhoseini1723
@vahidhoseini1723 3 жыл бұрын
great, good job mitch.
@kgi259
@kgi259 2 жыл бұрын
It's worked to my project! Thanks a lot
@jhonesns
@jhonesns 2 жыл бұрын
Thanks, it worked for me, I'm really happy, thank you so much!
@gigajoules6636
@gigajoules6636 4 жыл бұрын
So I have my recyclerview positioned inside of a fragment and want to make it so any image I press inside of my recyclerview is highlighted / selected when i do so. How do I acheive this? I have the debug window which states "Image n" pressed correcly when I click on an image, I'm just a little lost as to how I can get a handle on the imageviews from here.
@danylfernandes5903
@danylfernandes5903 5 жыл бұрын
Hey Mitch! Would you make a short video on how to make an expandable recyclerview. Each list item expands to show sub list items Thanks.
@GauravLonkar
@GauravLonkar 5 жыл бұрын
Yes, please. We need that.
@enzowalker2118
@enzowalker2118 4 жыл бұрын
Look into Paging Library for Android Studio. Maybe that might be what you're referring to.
@JoJo-yu7hh
@JoJo-yu7hh 4 жыл бұрын
I can't do it I did everything as in the video it only works once when starting, after which it stops responding. It's probably because of the OnClickListener. Can it be because of the CardView that is in a different layout?
@thebluer4829
@thebluer4829 5 жыл бұрын
Can i ask sir? how about when i try using firebase onclick listener on adapter. how can i make it like that? because when i try to make constructor i got an error that i should use ValueEvenListener than OnClickListener and i got an error too when i use the getAdapterPositions null pointer
@andre0667
@andre0667 2 жыл бұрын
Straight to the point!
@marenlampprecht6947
@marenlampprecht6947 4 жыл бұрын
Wow!!! This is a great tutorial! Thank you :)
@samoramabuya6583
@samoramabuya6583 3 жыл бұрын
Listen to me now. Thanks bro. This helped me with a problem I was having.
@crissb9357
@crissb9357 2 жыл бұрын
Hello Mitch, I appreciate your effort to answer our questions from here, thank you very much. I want see how to implement RecyclerView with multiView items and clickListener method in Java. It is possible ? I already work on this, but I got an error when I try to add more different xml items in RecyclerView(notifyItemInserted(0) didn't works).
@nonamenoname3144
@nonamenoname3144 2 жыл бұрын
Thank you very much, you make me understand interfaces
@chibakusanimations7316
@chibakusanimations7316 3 жыл бұрын
Thanks for the tutorial! Is it ok to remover the "OnNoteClickListener"in the ViewHolder constructor and just stick with the one on the adapter"mOnNoteListener"?
@GauthamKrishna07
@GauthamKrishna07 5 жыл бұрын
Hey Mitch. I have an error at 5:41. I already passed getApplicationContext and some other variables in the initialisation of Recycler adapter.
@isurubandara899
@isurubandara899 3 жыл бұрын
Thank you man, I have been using the wrong one that you mentioned. I did not know that Thank you again.
@sergeykuzmin8566
@sergeykuzmin8566 4 жыл бұрын
Thank you so much. It helped me with my project
@jalstudioproduction6739
@jalstudioproduction6739 4 жыл бұрын
How this can apply with a different code. I mean, I follow the tutorial from Coding in Flow in FirebaseUI - FirestoreRecyclerAdapter. I want to create a new activity from recycleView that connected in Firebase?
@LiubomyrFatsiievych
@LiubomyrFatsiievych 2 жыл бұрын
Great tutorial, thank u so much!
@nawazkamboo8750
@nawazkamboo8750 2 жыл бұрын
you're awesome dude. Really it is the Best Practice Way!! My Issue was solved
@hocineguebbas4016
@hocineguebbas4016 4 жыл бұрын
Thank you so match . you're the best ever.
@azammukhtar9011
@azammukhtar9011 5 жыл бұрын
Lol, i just wondering how to do that tommorow, very nice thank you !
@iAdrianT
@iAdrianT 5 жыл бұрын
Literally same LMAO
@rhupin5276
@rhupin5276 Жыл бұрын
I love this best practice video! By the way, does this also apply to the onClick method of onSwipe from ItemTouchHelper? I made a separate utility java files that extends ItemTouchHelper.SimpleCallBack. Should I also execute the commands inside this onClick, in the Activity class instead? Thanks so much in advance!
@prithvib8662
@prithvib8662 3 жыл бұрын
Your voice makes this sound like casually explained: programming
@67Diadem
@67Diadem 3 жыл бұрын
Great tutorial!! I have a question and I wanted to implement that on my project, how will you put a custom back button on new detail activity so that whenever a user press on custom back button then it goes back to recycler view list items. ..? Can you please help me with that?
@randy4443
@randy4443 4 жыл бұрын
Hi would you handle items inside the recyclerview click listener. For example, lets say there is a checkbox inside the recyclerview and you want to handle the click event .
@tanzimislam2395
@tanzimislam2395 4 жыл бұрын
Ty ma frnd. You have earned yourself a subscriber
@pikachubolt2001
@pikachubolt2001 4 жыл бұрын
My itemclicklistener interface doesnt work when I change the dataset with notifydatasetchanged()?, also my notifydatasetchanged() doesnt work when i put everything on oncreateview in my fragment where I have my recyclerview, but my interface works. by what I mean by that is i am using buttons to categorize my items in recyclerview, but they don't work since on oncreateview i already have items query'd for all, but when i take that away and my buttons work, but my listener doesnt trigger when i click my items
@soja0524
@soja0524 5 жыл бұрын
It was such a great explaination. Thanks1
@enriqueajin6016
@enriqueajin6016 3 жыл бұрын
Helped a lot. Thank you :)
@DrHoffVan
@DrHoffVan 5 жыл бұрын
thanks for the new and optimal way thanks a lot
@wertin200
@wertin200 4 жыл бұрын
Do you have any tips for navigate from one fragment to another fragment? Some context so that you can beter understand my problem I am currently building a pokedex, I have fragment with a recyclerView where all the pokemons are shown. Now I want to make a fragment where you can see the details for a specific pokemon. But when i try your method i can't base the pokedex fragment to the adapter class. Do you have any tips or something i should look up?
@nicolasvantsis6166
@nicolasvantsis6166 4 жыл бұрын
Hi and thank you for all this amazing videos. I have a question. Can you tell me please how can I set an OnClickListener in a particular item with this method? Like a delete button or imageView... I'm coding only 2 month and it's a bit difficult for me to understand everything. Thank you
@coquirivva
@coquirivva 3 жыл бұрын
Hi Mitch, what if you have more than one click in the recyclerview item, such as a button, beside the main item.
@codingwithshafi2019
@codingwithshafi2019 5 жыл бұрын
when using recyleview in fragment, my constructor is itemByConveyanceIdAdapter = new ItemByConveyanceIdAdapter(context,items,this) , this getting wrong . suggestion to Change 3rd parameter of method 'ItemByConveyanceIdAdapter' from 'OnNoteListener' to 'Callback'
@rishankyashu1121
@rishankyashu1121 4 жыл бұрын
wow..... nice explained iwas stuck on this problem for more than a day.....
@lemmynjaria65
@lemmynjaria65 3 жыл бұрын
Awesome!!! thanks a bunch
@gyuhyunchoi1941
@gyuhyunchoi1941 2 жыл бұрын
thanks for the great video! 👍
@alpertemell
@alpertemell 4 жыл бұрын
thanks, i implemented it to my code easily.
@hectorfabianvignolo9960
@hectorfabianvignolo9960 4 жыл бұрын
Mil gracias desde Argentina!!!
Sending Data to a New Activity with Intent Extras
8:21
CodingWithMitch
Рет қаралды 35 М.
DO NOT do this in a Software Engineering Interview
7:59
CodingWithMitch
Рет қаралды 9 М.
- А что в креме? - Это кАкАооо! #КондитерДети
00:24
Телеканал ПЯТНИЦА
Рет қаралды 7 МЛН
Slow motion boy #shorts by Tsuriki Show
00:14
Tsuriki Show
Рет қаралды 2,9 МЛН
ТАМАЕВ УНИЧТОЖИЛ CLS ВЕНГАЛБИ! Конфликт с Ахмедом?!
25:37
MVVM vs. MVI - Understand the Difference Once and for All
18:40
Philipp Lackner
Рет қаралды 33 М.
RecyclerView Item Click | Best Practice Way
8:06
Practical Coding
Рет қаралды 92 М.
Programming Is NOT Enough | Add these 7 skills…
13:19
Travis Media
Рет қаралды 415 М.
TypeScript: Should you use Types or Interfaces?
4:06
Matt Pocock
Рет қаралды 151 М.
RecyclerView | Everything You Need to Know
25:07
Practical Coding
Рет қаралды 131 М.
I've been using Redis wrong this whole time...
20:53
Dreams of Code
Рет қаралды 339 М.
iOS Development is Easier than Android Development (VLOG)
20:41
CodingWithMitch
Рет қаралды 52 М.
JavaScript Visualized - Event Loop, Web APIs, (Micro)task Queue
12:35