This video is part of a course named “SQLIte for Beginners 2019”. It’s free and available on my website:
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:
↻
➤Source Code:
↻
Nguồn:https://wijstaanvooronzegrondrechten.org/
Ty ma frnd.
You have earned yourself a subscriber
Can you more precisely explain why the previous method of onclickListener was bad practice?
Mitch please let me know how to sort Tablayout Titles I have 8 recipes in horizontal Tablayout.
Explaining what you code was doing as you typed, and at the end to summarized really helped!! Awesome tutorial!!
Hello how you can implement a popup menu in the notelistener as u know the popupmenu needs a view so how i can set up? and another question is, what recomend a popup menu or a context menu? in my app i have to select in a menu to wich activity i want to go
thanks for ur answer 🙂
great video Mitch. thank you.
there were like a gazillion comments (I know it's actually 202 :D) so I don't know if this has been asked before. I didn't get one thing. why each ViewHolder must have its own OnNoteListener? what if we did this instead:
* pass the OnNoteListener to Adapter (and set it as its field)
* ViewHolder implements the OnClickListener
* in ViewHolder's onClick method, we call Adapter's OnNoteListener's onClick
* pass 'this' to itemView's setOnClickListener method.
Am I missing sth? Is sth wrong with this?
Thank you so match . you're the best ever.
it is useful tutorial
Thanks
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 ?
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
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?
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?
sir plez do this plez.
@Override
public void onClick(View v) {
final Intent intent;
switch (getAdapterPostion()){
case 0:
intent = new Intent(context, FirstActivity.class);
break;
case 1:
intent = new Intent(context, SecondActivity.class);
break;
…
default:
intent = new Intent(context, DefaultActivity.class);
break;
}
context.startActivity(intent);
}
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
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!
Mil gracias desde Argentina!!!
This was such a god sent….Thank you for uploading this. Such an elegant solution.
thank you very much frnd , god on you
God bless you Mitch! It works like a charm!
This has really confused me. Am getting my data in the mainactivity from a ViewModel from room database.My problem is how to i pass it to the adapter.I also want to send that data to next activity using parcelable.
I understand how you would intent but how would you intent if each recycler holder should intent to different things. I tried an if statement with posistion value but that didnt work for me
Clearly explained, plus you made it so easy.
Thanks!
hey mitch, can you give me some advice about parent-child recyclerview? example on parent-Recyclerview i have list country (USA) and when im click the item, passing to child-recyclerview list name of city (New York, LA, Las Vegas, etc)
Just fantastic! Finally someone who can break down a myriad of core topics into a one simple brain folder!!
great and easy video new sub!
Hey Mitch, I was wondering if it's okay to implement onClickListeners inside onCreateViewHolder method of the adapter? I have implemented it and it works fine but I want to know if it's wrong in terms of performance and optimization?
Thanks for making this! Really helped me out!
the video is really helpful, but it should be much easier than this. the same functionality in Swift/Objective-C is only a few lines of codes