RecyclerView item Click using Interface | Advanced Way | Android

  Рет қаралды 49,830

Mafia Codes

Mafia Codes

Күн бұрын

In this video you will learn how to create an onClick Listener using an Interface. This is the best practice of implementing an onClick listener in Recycler view.
🚀Deploy NodeJs app: zeet.co/r/yourstruly
(One FREE project forever 😘)
In 60 seconds • How to Deploy a NodeJs...
FREE $100 credit @Digital Ocean: m.do.co/c/3208f08b3324
Patreon: / trulymittal
Subscribe: kzfaq.info...
⭐ Kite is a free AI-powered coding assistant that will help you code faster and smarter. The Kite plugin integrates with all the top editors and IDEs to give you smart completions and documentation while you’re typing. I've been using Kite for 6 months and I love it! www.kite.com/get-kite/?...
#RecyclerView (Basic Setup): • Recycler View with com...
Github(Tutorial): github.com/trulymittal/Recycl...
RecyclerView: developer.android.com/guide/t...
RecyclerView(dependency): developer.android.com/guide/t...
---------------
More useful videos
---------------
#ViewModel: • View Model | Live Data...
#Retrofit: • RETROFIT Tutorial (v 2...
#WorkManager: • Work Manager | Android...
#KeyframeAnimations: • Keyframe Animations wi...
#CollapsingToolbar Layout: • Collapsing Toolbar Lay...
#BottomNavigation View: • Bottom Navigation View...
#NavigationComponent: • Navigation Component |...
#NightMode: • Night Mode | Dark Mode...
#ButterKnife: • Butter Knife | Field a...
SplashScreen: • Splash screen | Launch...
Singletons: • Singletons | What When...
---------------
What I use
---------------
Mouse: amzn.to/2O9RJtu
Keyboard: amzn.to/2qxajCU
Keyboard 2: amzn.to/2XDWH4X
Monitor: amzn.to/2pDg7dH
Processor: amzn.to/347WWIb
RAM: amzn.to/2QEkUqw
Graphics: amzn.to/33aBrF4
Microphone: amzn.to/2DabdI9
#yoursTruly #tutorial #how-to #android

Пікірлер: 131
@dhfhf6776
@dhfhf6776 4 жыл бұрын
I am beginner in Android. For onItemCliking i have searched and seen 20+ videos and read 10-15 article about this. At last i have got a 100% explained video. Thank you so much sir 😍😍😍 From Bangladesh
@arbiealmeida87
@arbiealmeida87 3 жыл бұрын
No joke, this tutorial saved my butt. Huge huge thanks.
@CarlosAguilar-ue2um
@CarlosAguilar-ue2um 3 жыл бұрын
Same
@mohamedayad70
@mohamedayad70 3 жыл бұрын
after watching more than 8 or 9 videos finally i got it thanks bro
@mafiacodes
@mafiacodes 3 жыл бұрын
Glad u like it
@noodler911
@noodler911 3 жыл бұрын
@@mafiacodes 3:44 the this argument doesn't work. It provides ValueEventListener instead of recyclerViewClickInterface. What can I do?
@yogeshwarbirangal
@yogeshwarbirangal 4 жыл бұрын
Thank you man I wanted this from long time. I didn't know this method i was searching this method from long on Internet but couldn't find better implementation. Once again thank you.
@mafiacodes
@mafiacodes 4 жыл бұрын
Subscribe like share😊
@Sukhendusadhukhan
@Sukhendusadhukhan 4 жыл бұрын
You are really great. Thank you so much. I wanted this for a long time. I didn't know this method I was searching for this method from long on the Internet but couldn't find better implementation. Once again thank you.
@ClintonSiegel
@ClintonSiegel 3 жыл бұрын
Thank you very much! This was super helpful and so well done! Greatly appreciated!
@mafiacodes
@mafiacodes 3 жыл бұрын
Glad u like it
@sanketrai1303
@sanketrai1303 3 жыл бұрын
this tutorial really helped me thanks!!! i was about to giveup and then i saw this video and solved my problem thanks a ton !!!
@hocineguebbas4016
@hocineguebbas4016 4 жыл бұрын
waww. very simple and straight forward. thank you sir.
@mandalsalman
@mandalsalman 3 жыл бұрын
Thank you bro. Quite easy to understand.
@jain78343
@jain78343 3 жыл бұрын
Nice clear Explanation. Thank You :)
@Servidor_Publico_do_Ancapistao
@Servidor_Publico_do_Ancapistao 2 жыл бұрын
2021 almost 2022 and this is how you still want to do it. Thank you very much, I spent my whole day angry as fuck because I simple did not knew how to do it.
@miguelnuno928
@miguelnuno928 Жыл бұрын
Thank so much for this video.
@chiquito.y.panzon
@chiquito.y.panzon 3 жыл бұрын
Nice implementation, thanks you
@handsomeman5098
@handsomeman5098 3 жыл бұрын
very detail dan it works. thank you
@hhh48222
@hhh48222 2 жыл бұрын
Awesome explanation
@akhano2142
@akhano2142 2 жыл бұрын
this tutorial help me alot thank you bro.
@clips2613
@clips2613 Жыл бұрын
Thank you so much!
@ANKITKUMAR-ed9qj
@ANKITKUMAR-ed9qj 3 жыл бұрын
I finally understand it, thanks alot can you make a video about how i can manage my layout for different screen sizes and how to design it?🙏🙏
@ritikaans
@ritikaans 3 жыл бұрын
Finally, Today I got to know how it works ... Many thanks
@mukeshroy3858
@mukeshroy3858 2 жыл бұрын
great explanation sir... thanks a lot
@ankitdhopate5360
@ankitdhopate5360 4 жыл бұрын
Really explained well bro...!!!!!
@ranggasuryaprayoga5997
@ranggasuryaprayoga5997 2 жыл бұрын
Thank you very much sir
@captnrango6029
@captnrango6029 3 жыл бұрын
Very Good way to explain
@Anshukumar-pd8ur
@Anshukumar-pd8ur 2 жыл бұрын
Great job bro
@mafiacodes
@mafiacodes 2 жыл бұрын
Subscribe like share
@internetuser6602
@internetuser6602 2 жыл бұрын
THANKS SO MUCH. YOU SAVE ME
@RashiRitu10
@RashiRitu10 2 жыл бұрын
Thank you so much
@mafiacodes
@mafiacodes 2 жыл бұрын
You're most welcome subscribe like share
@elpirato5428
@elpirato5428 3 жыл бұрын
muchas gracias!
@venkatsai563
@venkatsai563 5 ай бұрын
this help alot bro
@aneeshahamed2490
@aneeshahamed2490 3 жыл бұрын
thanks bro🙏
@marcodeheza5981
@marcodeheza5981 4 жыл бұрын
Thank! Is working OK
@retlawam01
@retlawam01 4 жыл бұрын
No sabes cuanto tiempo he buscado hacer esto
@mafiacodes
@mafiacodes 4 жыл бұрын
me alegro de que te haya gustado, suscríbete como compartir
@prathiv5203
@prathiv5203 4 жыл бұрын
super bro plz upload many things from android studio
@mafiacodes
@mafiacodes 4 жыл бұрын
Watch the entire playlist there’s much more
@mohamedjakhrouti3556
@mohamedjakhrouti3556 3 жыл бұрын
thanks for video i have a question if ithem f listview or recyclerview contains three buttons and every button lanch activity diferent of the others how to add a click listener of them thanks again
@sepa1234
@sepa1234 2 жыл бұрын
tnks
@mafiacodes
@mafiacodes 2 жыл бұрын
subscribe like share
@kanhaiyatulsyan7560
@kanhaiyatulsyan7560 3 жыл бұрын
great explanation....but it would have been so easy if google themselves have provided an easy way to do it...!!!!
@ahsansyed4146
@ahsansyed4146 4 жыл бұрын
thanks buddy :)
@mafiacodes
@mafiacodes 4 жыл бұрын
Subscribe like share 😊
@ahsansyed4146
@ahsansyed4146 4 жыл бұрын
@@mafiacodes i have a question bro. how can I open specific fragment/activity on a specific position and where I need to code in Adapter or fragment/activity? and how ?
@mafiacodes
@mafiacodes 4 жыл бұрын
You can open it from both places, but the proper way is to open from activity or fragment in which this recycler view resides and that was the whole purpose of this video.
@sitaramgangode912
@sitaramgangode912 4 жыл бұрын
Thank you sir I need your guidance. I want to open new different activity from every item in recyclerview. So I think I should use switch case to perform a task. But I don't know how to do it. Please guide for the same.
@sitaramgangode912
@sitaramgangode912 4 жыл бұрын
I have used switch case in Recyclerview to open new activities. When items are not filtered it works perfectly. But when it is filtered wrong activity is opened. I think it happens because filtered items take upper position. It happens due to it. I don't know how to come over it. Please guide about it.
@mafiacodes
@mafiacodes 4 жыл бұрын
Watch my video on search filter and see if that helps kzfaq.info/get/bejne/ebqmrdKH2bHTemw.html
@tothepoint1560
@tothepoint1560 2 жыл бұрын
Same problems i am facing.
@umerqaisar6015
@umerqaisar6015 3 жыл бұрын
shukria
@syedshoaib3100
@syedshoaib3100 4 жыл бұрын
What if we use firebase recycler adapter where we have to initialize interface, in firebaseRecyclerAdapter method above on BindView???
@mafiacodes
@mafiacodes 4 жыл бұрын
the same way as its described here,,,
@MrAziz5152
@MrAziz5152 3 жыл бұрын
please use the dark mode for code window. BTW your tutorial are really helpful.
@fullgamingindia
@fullgamingindia 3 ай бұрын
what happen if we implements this interface in two activity classes and call this from recycler view. method from both classes will be called or not?
@jigneshraval6880
@jigneshraval6880 4 жыл бұрын
nice sir
@mafiacodes
@mafiacodes 4 жыл бұрын
Subscribe like share
@moazelsawaf2000
@moazelsawaf2000 4 жыл бұрын
Thanks a lot sir
@mafiacodes
@mafiacodes 4 жыл бұрын
Subscribe like share 😊
@helenh2442
@helenh2442 4 жыл бұрын
what is getApaterposition?? I can't see all code of adapter class
@sleepydev4700
@sleepydev4700 3 жыл бұрын
Its such a great explanation. But, could you explain why do we need an interface instead of making a method(e.g. handleItemClick(int position) ) in MainActivity for handling item click, then creating instance of MainActivity in the Adapter. It would be mainActiviy.handleItemClick(position)
@mafiacodes
@mafiacodes 3 жыл бұрын
Perfectly wrong 😑, it wud unnecessarily create a memory overhead, and most likely it won’t work as u will have multiple instances of the same activity
@rajarshimandal3235
@rajarshimandal3235 3 жыл бұрын
Passing "this" to adapter is not accepted, in constructor it asked to cast to valueevent listener, all errors gone but app crashed, any help plz?
@zubaer21
@zubaer21 3 жыл бұрын
Brother how can i implement recyclerview on click textview text change. Suppose a recyclerview has a 3 textview. I want when i click on whole view one textview show "P" and background color will be green. Another click will be background red and text A. Thank you Please help bro.
@ageingdragon8132
@ageingdragon8132 Жыл бұрын
will you consider one day doing this in kotlin??
@suhailzack9075
@suhailzack9075 3 жыл бұрын
i am not able to call the RecyclerviewInterface inside my adapter any suggestions?
@anandmayeemaity7123
@anandmayeemaity7123 2 жыл бұрын
for passing interface in fragment "this " is not working , how can i pass interface in fragment like you did in Activity??
@mafiacodes
@mafiacodes 2 жыл бұрын
basically this represent the activity, so you can pass in your fragments context for "this"
@solvinglife6658
@solvinglife6658 2 жыл бұрын
How can we use this with checkbox...urrgently needed....please
@user-jh7zx4jg1y
@user-jh7zx4jg1y 2 жыл бұрын
Thank uu. Do you do freelancing??
@mafiacodes
@mafiacodes 2 жыл бұрын
Yes you can contact me on yourstruly2607@gmail.com
@67Diadem
@67Diadem 3 жыл бұрын
Great tutorial. But I have a question. Can we do that if we click on any movie title and should open a new activity that display the description of that particular movie. For example if I click black panther then it should display the details of black panther and if we click on Iron man then it should display the iron man description. If yes then can you help me? I need it ASAP please
@mafiacodes
@mafiacodes 3 жыл бұрын
simply start the new activity
@67Diadem
@67Diadem 3 жыл бұрын
@@mafiacodes thanks a lot for the help... I have one more question that I'am making an app on story, that will show list of story in the list view with the help of API using volley library and recycler view. I also want to implement visitors or views count, meaning whenever a user click on a particular list then it will increment the view by one. For that visitors increment count I have extra API, but I'am confused that where to use that API as post method in adapter class? or in main activity class... Can you help me with this...?
@saranshagarwal2500
@saranshagarwal2500 4 жыл бұрын
Boss Please Make Video on How to open the fragment. when we click on the item of recyclerview.
@noobplayer8975
@noobplayer8975 4 жыл бұрын
how to get details data and send into fragment class
@bug9702
@bug9702 3 жыл бұрын
Hello ,Thank you for your knowledge also I have a quesiton I'm asking to understand why we didn't define onClickte directly inside the viewholder
@mafiacodes
@mafiacodes 3 жыл бұрын
What if u want to access or do something from activity or fragment? That is why.
@bug9702
@bug9702 3 жыл бұрын
​@@mafiacodes thank you for answering
@noorullah5946
@noorullah5946 3 жыл бұрын
Thanks a million bro...its helped me But what if we want to implement clickListener on a single view in recyclerView item (e.g. delete button or favorite button on the recyclerView item)...any help will be appreciated
@mafiacodes
@mafiacodes 3 жыл бұрын
Call the interface method from that onclick view
@dagher.a247
@dagher.a247 4 жыл бұрын
If you can tell me, how can I use this way for a recyclerview inside another recyclerview,
@mafiacodes
@mafiacodes 4 жыл бұрын
Implement interface in recycler adapter for child recycler adapter or in main activity or fragment implement the interface
@4dn907
@4dn907 3 жыл бұрын
Osm Bro, plz change your android s theme
@flyingDude
@flyingDude 4 жыл бұрын
Please make video for multiple image picker
@mafiacodes
@mafiacodes 4 жыл бұрын
will try to do that bro...till then SUBSCRIBE LIKE SHARE 😉
@awaiz3649
@awaiz3649 4 жыл бұрын
Hey,In item view onclicklistner it is showing me Nonstatic method cannot be referenced from a static context..please help.. Cardonclick.OncardClick(getAdapterpostion()); Here Iam getting problem .OncardClick is showing error as Non static method cant be referenced from static context..
@mafiacodes
@mafiacodes 4 жыл бұрын
Share code on GitHub
@awaiz3649
@awaiz3649 4 жыл бұрын
@@mafiacodes solved it bro thanks for reply...❤
@asifiqbal1261
@asifiqbal1261 4 жыл бұрын
Sir, which theme r u using? seems nice.
@mafiacodes
@mafiacodes 4 жыл бұрын
Like the video then i’ll tell 😉 . . It is google developers theme
@asifiqbal1261
@asifiqbal1261 4 жыл бұрын
@@mafiacodes Thanks Sir :)
@mediahafalan6305
@mediahafalan6305 3 жыл бұрын
Bro.. can you guide me how to solve my issue.. i stack for 2 day... i have class and method for animate flipcard in myActivity its call. FlipView.flipTheView(); and i want to use this class in my recycleView. if i write code like your video Its work perfectly but its call by manually clicking.. in my case iwant to call this method using another triger not by clicking.. how can i do something like that?
@vamsi1871
@vamsi1871 4 жыл бұрын
Sir i need how to save images in blob in room db
@mafiacodes
@mafiacodes 4 жыл бұрын
You can create a column for blob and then can store bytes in that column, the video will come when i start room db somewhr in 4/6days
@7days280
@7days280 4 жыл бұрын
sir my recycler view is not updating plz help even after trying the notifyItemRemoved
@mafiacodes
@mafiacodes 4 жыл бұрын
Share code on GitHub
@pronavsandhu
@pronavsandhu 3 жыл бұрын
thank you, buti don't know what i am doing wrong its not working for me, i have recyclerview with grid layout manager in a fragment .
@mafiacodes
@mafiacodes 3 жыл бұрын
Share the code on GitHub
@ryanben3988
@ryanben3988 3 жыл бұрын
Do not pass 'this' as a parameter , instead pass the .this , just from having the same problem. i.e. homeQuestionsRecyclerViewAdapter adapter = new homeQuestionsRecyclerViewAdapter(tempSearchQuestionArray, getActivity(), homeFragment.this);
@pronavsandhu
@pronavsandhu 3 жыл бұрын
@@ryanben3988 legend !! Thank you Gonna try this
@venkatm6324
@venkatm6324 4 жыл бұрын
onclick method open new page (other click same page open but only change data)
@mafiacodes
@mafiacodes 4 жыл бұрын
I dint get what you wanna know? Please elaborate
@ananaspowa5894
@ananaspowa5894 4 жыл бұрын
@@mafiacodes probably he intended starting a new activity, using only one not one for each item, and changing the data shown depending on what item you clicked on, not sure though... ( I could find it very useful too, but I think it's a bit complex)
@techroy2061
@techroy2061 2 жыл бұрын
It is not working in fragment... Onclick Interface pass error in fragment
@nelsonmunthe4571
@nelsonmunthe4571 4 жыл бұрын
I'm from indonesia thanks for sharing. Can you make the sub title?
@mafiacodes
@mafiacodes 4 жыл бұрын
U. An turn on subtitles from KZfaq settings. I guess that would work.
@nelsonmunthe4571
@nelsonmunthe4571 4 жыл бұрын
Still same bro, subtitle still nothing
@noodler911
@noodler911 3 жыл бұрын
3:44 the this argument doesn't work. It provides ValueEventListener instead of recyclerViewClickInterface. What can I do?
@mafiacodes
@mafiacodes 3 жыл бұрын
Share code
@noodler911
@noodler911 3 жыл бұрын
@@mafiacodes package com.example.popina; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import android.os.Bundle; import com.google.firebase.database.DataSnapshot; import com.google.firebase.database.DatabaseError; import com.google.firebase.database.DatabaseReference; import com.google.firebase.database.FirebaseDatabase; import com.google.firebase.database.ValueEventListener; import java.util.ArrayList; import java.util.List; public class klantMenu extends AppCompatActivity implements HelperAdapter.OnItemListener{ //;hier private RecyclerView mRecyclerView; List fetchData; RecyclerView recyclerView; HelperAdapter helperAdapter; DatabaseReference databaseReference; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_klant_menu); recyclerView = findViewById(R.id.recyclerview); recyclerView.setLayoutManager(new LinearLayoutManager(this)); fetchData = new ArrayList(); String naamRestaurant = getIntent().getStringExtra("naamRestaurant"); databaseReference = FirebaseDatabase.getInstance().getReference("restaurants/users/" + naamRestaurant + "/menu"); databaseReference.addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(@NonNull DataSnapshot snapshot) { for(DataSnapshot ds: snapshot.getChildren()){ FetchData data = ds.getValue(FetchData.class); fetchData.add(data); } helperAdapter = new HelperAdapter(fetchData, this); recyclerView.setAdapter(helperAdapter); } @Override public void onCancelled(@NonNull DatabaseError error) { } }); } @Override public void onItemClick(int position) { //hier System.out.println(position); } }
@noodler911
@noodler911 3 жыл бұрын
@@mafiacodes Why do you skip me sir?
@mafiacodes
@mafiacodes 3 жыл бұрын
Need to share code on GitHub and also mention the problem in readme.md file
@noodler911
@noodler911 3 жыл бұрын
@@mafiacodes thanks man but I just fixed it. Thanks anyway!
@yutaitadori7318
@yutaitadori7318 3 жыл бұрын
Aapne kaha se sikha h android development?
@mafiacodes
@mafiacodes 3 жыл бұрын
Android docs and other stuff on youtube
@yutaitadori7318
@yutaitadori7318 3 жыл бұрын
@@mafiacodes please share some resources
@yutaitadori7318
@yutaitadori7318 3 жыл бұрын
@@mafiacodes reading docs takes much efforts then too after hours of researching I don't find the relevant stuff and if I found that then I don't understand how's that working . Please help 🙏
@omkeshwani1344
@omkeshwani1344 3 жыл бұрын
Sir give me your address I will come to your place and give you a huge gift with lots of thanks I can't express my happiness I was struggling with this from past 7hours I haven't watched any other video of yours still subscribed 🙂🙂🙂🙂😊😃
@mafiacodes
@mafiacodes 3 жыл бұрын
Thank you, stay tuned...
@deepamitchaudhary
@deepamitchaudhary 3 жыл бұрын
Please Please Please help Hi Sir, Actually, I have two apps in a single project, 1st is a customer app and 2nd one is company app, both apps share the same firebase database. And both the apps are identical in terms of login and registration, When started writing code for the 2nd app, that time I copied 1st project and modified all the activities(android java code) as per my needs. The issue I am facing is when customers register in the customer app and then the same login credentials are being used to login in company app without registering to it or vice-versa. I don't understand why this is happening. I saw one thing that for both the project SHA-1 key is the same after generating from the android studio. I want to restrict login to without registering to it for both the apps, the one should be able to login in the app in which he/she has registered, not in 2nd app where he/she haven't registered, Kindly help me so that I can move forward with my development. Thanks & Regards, Amit Chaudhary
@mafiacodes
@mafiacodes 3 жыл бұрын
since ur using the same firebase project for authentication, so u cannot protect it, the user can log in with any app, since its using the same firebase auth database...
@dhfhf6776
@dhfhf6776 4 жыл бұрын
Sir, please help...OnItemClick successfully worked. But OOnLongClick not working. When I long clicked on an item then the app crashed... here is logcat result : java.lang.NullPointerException: Attempt to invoke interface method 'void com.example.recyclerviewpractice.ROnClickInterface.OnLongItemClick(int)' on a null object reference at com.example.recyclerviewpractice.MyViewHolder$2.onLongClick(MyViewHolder.java:26) Here is the interface: public interface ROnClickInterface { void OnItemClick(int position); void OnLongItemClick(int position); } here is ViewHolder code: itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { rOnClickInterface.OnItemClick(getAdapterPosition()); } }); itemView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { rOnClickInterface.OnLongItemClick(getAdapterPosition()); return true; } }); here is action: @Override public void OnItemClick(int position) { Toast.makeText(this, cityNames.get(position), Toast.LENGTH_SHORT).show(); } @Override public void OnLongItemClick(int position) { cityNames.remove(position); myAdapter.notifyItemRemoved(position); }
@jonilsoncoelho8930
@jonilsoncoelho8930 2 жыл бұрын
Thank you so much!
@ranggasuryaprayoga5997
@ranggasuryaprayoga5997 2 жыл бұрын
Thank you very much sir
Swipe gestures in Recycler View | Android
18:47
Mafia Codes
Рет қаралды 61 М.
RecyclerView | Everything You Need to Know
25:07
Practical Coding
Рет қаралды 130 М.
когда повзрослела // EVA mash
00:40
EVA mash
Рет қаралды 4,5 МЛН
БОЛЬШОЙ ПЕТУШОК #shorts
00:21
Паша Осадчий
Рет қаралды 10 МЛН
100❤️
00:19
MY💝No War🤝
Рет қаралды 21 МЛН
Multi view RecyclerView | getItemViewType() | Android
15:03
Mafia Codes
Рет қаралды 38 М.
RecyclerView OnClickListener (Best practice way)
11:48
CodingWithMitch
Рет қаралды 291 М.
RecyclerView Item Click | Best Practice Way
8:06
Practical Coding
Рет қаралды 92 М.
OnClick Listener using Interface in RecyclerView
7:50
Mafia Codes
Рет қаралды 7 М.
RecyclerView in Android Studio using Kotlin | Android Knowledge
12:11
Android Knowledge
Рет қаралды 13 М.
Drag and drop Reorder in Recycler View | Android
7:05
Mafia Codes
Рет қаралды 31 М.
Add OnClick Listener To RecyclerView | Android RecyclerView Tutorial
6:21
когда повзрослела // EVA mash
00:40
EVA mash
Рет қаралды 4,5 МЛН