RecyclerView item Click using Interface | Advanced Way | Android

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ธ.ค. 2024

ความคิดเห็น • 131

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

    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

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

    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?

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

    No joke, this tutorial saved my butt. Huge huge thanks.

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

    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😊

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

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

    Awesome explanation

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

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

    Thank so much for this video.

  • @ANKITKUMAR-ed9qj
    @ANKITKUMAR-ed9qj 4 ปีที่แล้ว +4

    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?🙏🙏

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

    will you consider one day doing this in kotlin??

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

    Thank you very much sir

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

    great explanation sir... thanks a lot

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

    Thank you bro. Quite easy to understand.

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

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

    Finally, Today I got to know how it works ... Many thanks

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

    this tutorial help me alot thank you bro.

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

    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.

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

    very detail dan it works. thank you

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

    waww. very simple and straight forward. thank you sir.

  • @Anshukumar-pd8ur
    @Anshukumar-pd8ur 3 ปีที่แล้ว +1

    Great job bro

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

      Subscribe like share

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

    Very Good way to explain

  • @chiquito.y.panzon
    @chiquito.y.panzon 4 ปีที่แล้ว +1

    Nice implementation, thanks you

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

    Thank you so much!

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

    Nice clear Explanation.
    Thank You
    :)

  • @المبتسمدائما-ن4غ
    @المبتسمدائما-ن4غ 2 ปีที่แล้ว

    Thank uu. Do you do freelancing??

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

      Yes you can contact me on yourstruly2607@gmail.com

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

    THANKS SO MUCH. YOU SAVE ME

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

    Really explained well bro...!!!!!

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

    Thank you so much

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

      You're most welcome
      subscribe like share

  • @venkatsai563
    @venkatsai563 10 หลายเดือนก่อน

    this help alot bro

  • @fullgamingindia
    @fullgamingindia 8 หลายเดือนก่อน

    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?

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

    please use the dark mode for code window. BTW your tutorial are really helpful.

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

    Thank you very much! This was super helpful and so well done! Greatly appreciated!

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

    How can we use this with checkbox...urrgently needed....please

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

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

    thanks bro🙏

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

    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 th-cam.com/video/CTvzoVtKoJ8/w-d-xo.html

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

      Same problems i am facing.

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

      What if u want to access or do something from activity or fragment? That is why.

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

      ​@@mafiacodes
      thank you for answering

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

    muchas gracias!

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

    super bro plz upload many things from android studio

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

      Watch the entire playlist there’s much more

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

    No sabes cuanto tiempo he buscado hacer esto

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

      me alegro de que te haya gustado, suscríbete como compartir

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

    Sir, which theme r u using? seems nice.

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

      Like the video then i’ll tell 😉
      .
      .
      It is google developers theme

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

      @@mafiacodes Thanks Sir :)

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

    shukria

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

      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...?

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

    great explanation....but it would have been so easy if google themselves have provided an easy way to do it...!!!!

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

    Please make video for multiple image picker

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

      will try to do that bro...till then SUBSCRIBE LIKE SHARE 😉

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

    tnks

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

      subscribe like share

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

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

    Thank! Is working OK

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

    what is getApaterposition?? I can't see all code of adapter class

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

    i am not able to call the RecyclerviewInterface inside my adapter any suggestions?

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

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

      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

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

    for passing interface in fragment "this " is not working , how can i pass interface in fragment like you did in Activity??

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

      basically this represent the activity, so you can pass in your fragments context for "this"

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

      @@mafiacodes thanks man but I just fixed it. Thanks anyway!

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

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

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

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

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

    how to get details data and send into fragment class

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

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

      Call the interface method from that onclick view

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

    onclick method open new page (other click same page open but only change data)

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

      I dint get what you wanna know? Please elaborate

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

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

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

    It is not working in fragment...
    Onclick Interface pass error in fragment

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

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

      Share the code on GitHub

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

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

      @@ryanben3988 legend !! Thank you Gonna try this

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

      Share code on GitHub

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

      @@mafiacodes solved it bro thanks for reply...❤

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

    thanks buddy :)

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

      Subscribe like share 😊

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

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

      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.

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

    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?

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

    nice sir

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

      Subscribe like share

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

    Boss Please Make Video on How to open the fragment. when we click on the item of recyclerview.

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

    Osm Bro, plz change your android s theme

  • @7days280
    @7days280 4 ปีที่แล้ว

    sir my recycler view is not updating plz help even after trying the notifyItemRemoved

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

      Share code on GitHub

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

    Sir i need how to save images in blob in room db

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

      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

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

    I'm from indonesia thanks for sharing. Can you make the sub title?

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

      U. An turn on subtitles from TH-cam settings. I guess that would work.

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

      Still same bro, subtitle still nothing

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

    Thanks a lot sir

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

      Subscribe like share 😊

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

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

      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);
    }

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

      Thank you, stay tuned...

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

    Thank you very much sir

  • @clips2613
    @clips2613 2 ปีที่แล้ว +1

    Thank you so much!