RecyclerView OnClickListener (Best practice way)

แชร์
ฝัง
  • เผยแพร่เมื่อ 9 ม.ค. 2019
  • 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

  • @jarrodthoma1866
    @jarrodthoma1866 3 ปีที่แล้ว +2

    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 ปีที่แล้ว +1

    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!

  • @milkjpg
    @milkjpg 5 ปีที่แล้ว +6

    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!!!

  • @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

  • @josepenasanchez1491
    @josepenasanchez1491 4 ปีที่แล้ว +2

    Explaining what you code was doing as you typed, and at the end to summarized really helped!! Awesome tutorial!!

  • @joeypeters2916
    @joeypeters2916 4 ปีที่แล้ว +14

    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 ปีที่แล้ว +14

    God bless you Mitch! It works like a charm!

  • @huh_wtf
    @huh_wtf 4 ปีที่แล้ว +4

    This was such a god sent....Thank you for uploading this. Such an elegant solution.

  • @moazelsawaf2000
    @moazelsawaf2000 5 ปีที่แล้ว +8

    Thanks a lot ❤️
    This method is called inter fragment communication and we use it when we want our fragment to communicate with the activity...

  • @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 ปีที่แล้ว +8

    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

  • @Richie_
    @Richie_ 4 ปีที่แล้ว +14

    Coding with Mitch & Coding in Flow are the 2 best tutors on TH-cam.

  • @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

  • @ianrknowles
    @ianrknowles 3 ปีที่แล้ว

    Tried to get a recyclerview click listener working for hours - this tutorial finally cracked it - Thank you!

  • @ericsmith2405
    @ericsmith2405 4 ปีที่แล้ว +1

    Just fantastic! Finally someone who can break down a myriad of core topics into a one simple brain folder!!

  • @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 🙌

  • @codinginflow
    @codinginflow 5 ปีที่แล้ว +217

    Wow you must be a programmer or something

    • @codingwithmitch
      @codingwithmitch  5 ปีที่แล้ว +43

      😏

    • @goldwings1468
      @goldwings1468 5 ปีที่แล้ว +10

      Coding in Flow approves 😃

    • @anhchung7340
      @anhchung7340 4 ปีที่แล้ว +3

      funny :)

    • @ehtashamali821
      @ehtashamali821 4 ปีที่แล้ว +2

      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 ปีที่แล้ว +1

      Codingin Flow you too, you are a genius ;)

  • @ki11qwerty47
    @ki11qwerty47 4 ปีที่แล้ว +10

    omg!!! thanks a lot! i killed 1day to find best practice way for this )))

  • @sitibalqis8032
    @sitibalqis8032 5 ปีที่แล้ว +1

    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 😂

  • @dignitymashoko5437
    @dignitymashoko5437 5 ปีที่แล้ว +1

    Man you are the best, keep up you are saving the world.

  • @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!

  • @hugocc0318
    @hugocc0318 ปีที่แล้ว

    Omg I have learned more in this video than searching through a thousand forums, thank you very much

  • @themax734
    @themax734 4 ปีที่แล้ว

    Thanks Mitch! This was exactly what I needed.

  • @vladkondratiuk5886
    @vladkondratiuk5886 5 ปีที่แล้ว +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!

  • @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....

  • @dungenhero7159
    @dungenhero7159 3 ปีที่แล้ว

    I went to StackOverflow, couldn't find the solution. Then I found this. Worked like a charm. Thanks a lot

  • @madhuthakur472
    @madhuthakur472 5 ปีที่แล้ว +1

    Really appreciate the way you explain things .. made android easy for me ..

  • @user-dm1te2rj5u
    @user-dm1te2rj5u 5 ปีที่แล้ว +1

    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! >ㅁ

  • @josephridge3646
    @josephridge3646 3 ปีที่แล้ว +1

    Hey Mitch thank your for this !!!
    I appreciate the relay.

  • @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.

  • @sonuchristopherk2273
    @sonuchristopherk2273 4 ปีที่แล้ว

    amazingly short and easy to understand.. Keep rocking!

  • @martinsalcedoapps
    @martinsalcedoapps 4 ปีที่แล้ว

    Really simple, great explanation. Thanks Mitch.

  • @nikhilcsuvarna8829
    @nikhilcsuvarna8829 2 ปีที่แล้ว

    Thank you for this..I was searching whole day for this..🙌

  • @red2fire2
    @red2fire2 5 ปีที่แล้ว +16

    Cheers,
    This really helped

  • @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.

  • @IbnBattuta2
    @IbnBattuta2 5 ปีที่แล้ว +3

    Thanks. Great tutorial as usual.

  • @karagezify
    @karagezify 4 ปีที่แล้ว

    Thanks for making this! Really helped me out!

  • @mengmengliu6261
    @mengmengliu6261 3 ปีที่แล้ว

    simple and elegant, thank you so much!

  • @pikachubolt2001
    @pikachubolt2001 4 ปีที่แล้ว +1

    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!

  • @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.

  • @darshans9186
    @darshans9186 5 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

      I think next month I'm going to start posting shitty stuff

  • @samha1513
    @samha1513 5 ปีที่แล้ว +1

    Clear and to the point as always. Everytime I watch your video I learn something new. Thanks.

  • @switchend7776
    @switchend7776 5 ปีที่แล้ว +1

    quality teaching bro thank you! learned a lot

  • @BaldPL
    @BaldPL 4 ปีที่แล้ว

    Thanks for help! Good quality example of create own listener and use it in RecyclerView.

  • @aleksandrbut9604
    @aleksandrbut9604 5 ปีที่แล้ว

    thanks a lot, this is exactly what i was looking for

  • @patrickgichuki1789
    @patrickgichuki1789 4 ปีที่แล้ว

    Life and time saver! Thank you very much!

  • @constanzacirion8100
    @constanzacirion8100 3 ปีที่แล้ว

    this is exactly what i was looking for. thanks :)

  • @Thatbigx
    @Thatbigx 5 ปีที่แล้ว +2

    Thank you very much, helped a lot.

  • @javrz91
    @javrz91 4 ปีที่แล้ว

    Excellent! This really helped a lot! Thanks!

  • @ryujikomai8859
    @ryujikomai8859 4 ปีที่แล้ว

    Super helpful and straightforward. Thanks so much :)

  • @zadick2026
    @zadick2026 5 ปีที่แล้ว +2

    Thank you so much bro it saves my time

  • @arunachalamk1145
    @arunachalamk1145 5 ปีที่แล้ว +1

    keep doing bruh Great quality

  • @aslammamud6078
    @aslammamud6078 3 ปีที่แล้ว

    Your tutorial helped me a lot. thanks. all the best.

  • @Kevin-HB
    @Kevin-HB 3 ปีที่แล้ว

    Man, you help my life. THANK YOU SO MUCH!!!!!!

  • @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?

  • @jhonesns
    @jhonesns 2 ปีที่แล้ว

    Thanks, it worked for me, I'm really happy, thank you so much!

  • @vahidhoseini1723
    @vahidhoseini1723 3 ปีที่แล้ว

    great, good job mitch.

  • @abdulazizfahim2140
    @abdulazizfahim2140 3 ปีที่แล้ว

    Dude you are a LIFESAVER!!

  • @nawazkamboo8750
    @nawazkamboo8750 2 ปีที่แล้ว

    you're awesome dude. Really it is the Best Practice Way!!
    My Issue was solved

  • @isurubandara899
    @isurubandara899 3 ปีที่แล้ว

    Thank you man, I have been using the wrong one that you mentioned. I did not know that Thank you again.

  • @hocineguebbas4016
    @hocineguebbas4016 4 ปีที่แล้ว

    Thank you so match . you're the best ever.

  • @casenovo
    @casenovo 3 ปีที่แล้ว

    Awesome Work Dude.
    Really Appreciate it.

  • @samoramabuya6583
    @samoramabuya6583 3 ปีที่แล้ว

    Listen to me now. Thanks bro. This helped me with a problem I was having.

  • @marenlampprecht6947
    @marenlampprecht6947 4 ปีที่แล้ว

    Wow!!! This is a great tutorial! Thank you :)

  • @kgi259
    @kgi259 2 ปีที่แล้ว

    It's worked to my project! Thanks a lot

  • @demoscena1180
    @demoscena1180 5 ปีที่แล้ว +8

    Interesting. I was always using the "bad practice" way.

  • @enriqueajin6016
    @enriqueajin6016 3 ปีที่แล้ว

    Helped a lot. Thank you :)

  • @LiubomyrFatsiievych
    @LiubomyrFatsiievych 2 ปีที่แล้ว

    Great tutorial, thank u so much!

  • @vuphong2003
    @vuphong2003 4 ปีที่แล้ว +2

    Clearly explained, plus you made it so easy.
    Thanks!

  • @DrHoffVan
    @DrHoffVan 5 ปีที่แล้ว

    thanks for the new and optimal way thanks a lot

  • @MijanurRahman-jo1st
    @MijanurRahman-jo1st 5 ปีที่แล้ว

    your video is the best,thanks a lot

  • @soja0524
    @soja0524 5 ปีที่แล้ว

    It was such a great explaination. Thanks1

  • @gyuhyunchoi1941
    @gyuhyunchoi1941 2 ปีที่แล้ว

    thanks for the great video! 👍

  • @alpertemell
    @alpertemell 4 ปีที่แล้ว

    thanks, i implemented it to my code easily.

  • @sergeykuzmin8566
    @sergeykuzmin8566 4 ปีที่แล้ว

    Thank you so much. It helped me with my project

  • @vitalykrivolapov3163
    @vitalykrivolapov3163 4 ปีที่แล้ว

    Thank you very much! Very helped.

  • @rishankyashu1121
    @rishankyashu1121 4 ปีที่แล้ว

    wow..... nice explained iwas stuck on this problem for more than a day.....

  • @nonamenoname3144
    @nonamenoname3144 2 ปีที่แล้ว

    Thank you very much, you make me understand interfaces

  • @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!

  • @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.

  • @lemmynjaria65
    @lemmynjaria65 3 ปีที่แล้ว

    Awesome!!! thanks a bunch

  • @anshusharma5095
    @anshusharma5095 5 ปีที่แล้ว +1

    thankyou so much ..it works ...hurryyyyy

  • @tanzimislam2395
    @tanzimislam2395 4 ปีที่แล้ว +1

    Ty ma frnd.
    You have earned yourself a subscriber

  • @azammukhtar9011
    @azammukhtar9011 5 ปีที่แล้ว +4

    Lol, i just wondering how to do that tommorow, very nice thank you !

    • @iAdrianT
      @iAdrianT 5 ปีที่แล้ว +2

      Literally same LMAO

  • @GauthamKrishna07
    @GauthamKrishna07 5 ปีที่แล้ว +3

    Hey Mitch. I have an error at 5:41. I already passed getApplicationContext and some other variables in the initialisation of Recycler adapter.

  • @JoJo-yu7hh
    @JoJo-yu7hh 4 ปีที่แล้ว +1

    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?

  • @farnadtohidkhah1684
    @farnadtohidkhah1684 2 ปีที่แล้ว

    Thank you very much for your decent video

  • @milleniumtv908
    @milleniumtv908 4 ปีที่แล้ว

    This helped me a lots! Thanks very much

  • @thebluer4829
    @thebluer4829 5 ปีที่แล้ว +1

    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

  • @sachindeshapande7888
    @sachindeshapande7888 5 ปีที่แล้ว

    It's working... Thank you

  • @addinninggar1775
    @addinninggar1775 4 ปีที่แล้ว

    this really help mee thank uu !!

  • @hectorfabianvignolo9960
    @hectorfabianvignolo9960 4 ปีที่แล้ว

    Mil gracias desde Argentina!!!

  • @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.

  • @LoneAnimatorAnimations
    @LoneAnimatorAnimations 4 ปีที่แล้ว

    Thank-you!!! You should know, you're great!

  • @rishabh6904
    @rishabh6904 4 ปีที่แล้ว

    Thanks a lot and God Bless!!!

  • @modelonh
    @modelonh 3 ปีที่แล้ว

    Great vid, thanks!

  • @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"?

  • @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?

  • @andre0667
    @andre0667 2 ปีที่แล้ว

    Straight to the point!