RecyclerView OnClickListener (Best practice way)
HTML-код
- Опубликовано: 27 ноя 2024
- This video is part of a course named "SQLIte for Beginners 2019". It's free and available on my website: codingwithmitc...
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:
↻ codingwithmitc...
➤Source Code:
↻ github.com/mit...
Coding with Mitch & Coding in Flow are the 2 best tutors on RUclips.
Tried to get a recyclerview click listener working for hours - this tutorial finally cracked it - Thank you!
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.
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?
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!!!
Thanks a lot ❤️
This method is called inter fragment communication and we use it when we want our fragment to communicate with the activity...
I went to StackOverflow, couldn't find the solution. Then I found this. Worked like a charm. Thanks a lot
Omg I have learned more in this video than searching through a thousand forums, thank you very much
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....
Explaining what you code was doing as you typed, and at the end to summarized really helped!! Awesome tutorial!!
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!
Just fantastic! Finally someone who can break down a myriad of core topics into a one simple brain folder!!
Haha "brain folder". I like that
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
This was such a god sent....Thank you for uploading this. Such an elegant solution.
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 🙌
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
Did you find a way to
Go from one fragment to
Another fragment
And then to show the id that was passed through
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.
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.
God bless you Mitch! It works like a charm!
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.
This is gold among so much shitty stack answers i found. Much thanks for this explanation and BRILLIANT revision at the end.
Man you are the best, keep up you are saving the world.
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
Wow you must be a programmer or something
😏
Coding in Flow approves 😃
funny :)
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
Codingin Flow you too, you are a genius ;)
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.
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!
Your voice makes this sound like casually explained: programming
Interesting. I was always using the "bad practice" way.
Thank you for this..I was searching whole day for this..🙌
omg!!! thanks a lot! i killed 1day to find best practice way for this )))
I learned multiple new things today, this first being that you can actually implement multiple interfaces in a class declaration. I couldn't figure out how to get this to work (I'm using a cursor and SQLite db), but it turns out you can implement multiple interfaces by separating with commas.
Class Xyz implements Manager.Cursor, Adapter.Listener {
Ha! Thanks for the video, super helpful!
On another note, you should try using the room persistence library instead of the old "cursor" way with SQlite. I have a free course if you're interested. codingwithmitch.com/courses/sqlite-room-persistence-android/
@@codingwithmitch Thanks yeah I'll definitely try that out. It seems like a constant struggle finding what's been deprecated and what is still like 5 years old but still heavily used. I realized a little late into my project that (apparently) the Cursor is dead.
@@kneedeep185 that's why you gotta follow me. I do all the hard work for you
I am very happy to find your content. Excellent explanation, I have signed up for the full course on your website. Thank you!
Listen to me now. Thanks bro. This helped me with a problem I was having.
Really appreciate the way you explain things .. made android easy for me ..
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!
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.
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 😂
wow..... nice explained iwas stuck on this problem for more than a day.....
Thanks for help! Good quality example of create own listener and use it in RecyclerView.
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!
Clear and to the point as always. Everytime I watch your video I learn something new. Thanks.
Hey Mitch thank your for this !!!
I appreciate the relay.
you're awesome dude. Really it is the Best Practice Way!!
My Issue was solved
amazingly short and easy to understand.. Keep rocking!
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
I think next month I'm going to start posting shitty stuff
Your tutorial helped me a lot. thanks. all the best.
Thank you man, I have been using the wrong one that you mentioned. I did not know that Thank you again.
Really simple, great explanation. Thanks Mitch.
Man, you help my life. THANK YOU SO MUCH!!!!!!
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! >ㅁ
Clearly explained, plus you made it so easy.
Thanks!
Thanks Mitch! This was exactly what I needed.
Super helpful and straightforward. Thanks so much :)
Ty ma frnd.
You have earned yourself a subscriber
Dude you are a LIFESAVER!!
this is exactly what i was looking for. thanks :)
Life and time saver! Thank you very much!
Superb. Thank you sir. Very good tutorial
simple and elegant, thank you so much!
It's worked to my project! Thanks a lot
please make a video on passing object as an intent. Great video btw;)
@CodingWithMitch
You have just mentioned performance issues but please give a detailed explanation of performance issues in the old method and how this method solves it ?.
Awesome Work Dude.
Really Appreciate it.
Thanks, it worked for me, I'm really happy, thank you so much!
Thank you very much, you make me understand interfaces
Straight to the point!
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.
Yes, please. We need that.
Look into Paging Library for Android Studio. Maybe that might be what you're referring to.
Thanks. Great tutorial as usual.
Nice video. Very well explained.
Wow!!! This is a great tutorial! Thank you :)
Excellent! This really helped a lot! Thanks!
Lol, i just wondering how to do that tommorow, very nice thank you !
Literally same LMAO
Good explanation.
I find it at times difficult to see, what good practices are with anroid components.
The official documentation tends to give examples that are simple to understand, but are frequently adviced against.
e.g. in the case of making api call on the main thread.
great, good job mitch.
Thanks for making this! Really helped me out!
Dude...I was stuck on filtering one recyclerview from another for 3 days, then I implemented my onclick listeners like this, and now it works! thank you so much for this. Where can we find this by the way, is this on the documentation? Just know that you have saved my sanity xD
Sir, great video. Thank you. Greetings from Venezuela!
Mil gracias desde Argentina!!!
quality teaching bro thank you! learned a lot
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!
This helped me a lots! Thanks very much
No problemo
Thank you so much. It helped me with my project
Great tutorial, thank u so much!
Hi. Can you help explain how to implement OnClickListener to open url? I've searched everywhere but no solution found. Thanks.
thanks for the new and optimal way thanks a lot
Thank you so much bro it saves my time
Thank you so match . you're the best ever.
Thank you very much for your decent video
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.
Thank you very much! Very helped.
Cheers,
This really helped
thanks a lot, this is exactly what i was looking for
Hey nice tips but whats the interface for ? Why not handle the click in the onClick method with getAdapterPostion if you don't need to change anything in the views ?
Helped a lot. Thank you :)
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'
You saved my life
Tnk very helpful for me
Great video tutorial. Question!!!! How do I disable certain clicking positions ? For instance I don’t want note 5 to be clickable.
In that case you could try using the "position" value to find the ViewHolder you want to make unclickable and do something like setClickable(false)
This the aptest way I have found. Other implementation have got me bugs like onclick getting called twice.
But still I am struggling to add onClickListener to the child of ItemView.
thanks, i implemented it to my code easily.
Thanks for this mate, but why is it that I get -1 or no_position from getAdapterPosition sometimes when I delete things from the list?
the new activity is not opening on clicking a particular item once. I have to click it several random number of times after which the intent works. And this is happening with all the items.
Please help
Same to me (