RecyclerView item Click using Interface | Advanced Way | Android

Поделиться
HTML-код
  • Опубликовано: 9 ноя 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

  • @arbiealmeida87
    @arbiealmeida87 4 года назад +11

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

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

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

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

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

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

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

  • @hhh48222
    @hhh48222 3 года назад +1

    Awesome explanation

  • @miguelnuno928
    @miguelnuno928 2 года назад +1

    Thank so much for this video.

  • @ritikaans
    @ritikaans 3 года назад

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

  • @ranggasuryaprayoga5997
    @ranggasuryaprayoga5997 2 года назад +1

    Thank you very much sir

  • @mandalsalman
    @mandalsalman 4 года назад +1

    Thank you bro. Quite easy to understand.

  • @ageingdragon8132
    @ageingdragon8132 Год назад +1

    will you consider one day doing this in kotlin??

  • @mukeshroy3858
    @mukeshroy3858 2 года назад

    great explanation sir... thanks a lot

  • @akhano2142
    @akhano2142 3 года назад

    this tutorial help me alot thank you bro.

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

  • @kanhaiyatulsyan7560
    @kanhaiyatulsyan7560 3 года назад

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

  • @Anshukumar-pd8ur
    @Anshukumar-pd8ur 2 года назад +1

    Great job bro

  • @hocineguebbas4016
    @hocineguebbas4016 4 года назад +1

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

  • @handsomeman5098
    @handsomeman5098 3 года назад +1

    very detail dan it works. thank you

  • @prathiv5203
    @prathiv5203 4 года назад +2

    super bro plz upload many things from android studio

    • @mafiacodes
      @mafiacodes  4 года назад

      Watch the entire playlist there’s much more

  • @MrAziz5152
    @MrAziz5152 3 года назад

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

  • @RashiRitu10
    @RashiRitu10 3 года назад +1

    Thank you so much

    • @mafiacodes
      @mafiacodes  3 года назад

      You're most welcome
      subscribe like share

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

  • @internetuser6602
    @internetuser6602 2 года назад

    THANKS SO MUCH. YOU SAVE ME

  • @chiquito.y.panzon
    @chiquito.y.panzon 4 года назад +1

    Nice implementation, thanks you

  • @jain78343
    @jain78343 3 года назад

    Nice clear Explanation.
    Thank You
    :)

  • @ClintonSiegel
    @ClintonSiegel 3 года назад +1

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

  • @captnrango6029
    @captnrango6029 4 года назад

    Very Good way to explain

  • @fullgamingindia
    @fullgamingindia 7 месяцев назад

    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?

  • @jonilsoncoelho8930
    @jonilsoncoelho8930 2 года назад

    Thank you so much!

  • @venkatsai563
    @venkatsai563 9 месяцев назад

    this help alot bro

  • @ankitdhopate5360
    @ankitdhopate5360 4 года назад

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

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

  • @المبتسمدائما-ن4غ
    @المبتسمدائما-ن4غ 2 года назад

    Thank uu. Do you do freelancing??

    • @mafiacodes
      @mafiacodes  2 года назад

      Yes you can contact me on yourstruly2607@gmail.com

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

  • @sepa1234
    @sepa1234 3 года назад +1

    tnks

  • @umerqaisar6015
    @umerqaisar6015 3 года назад +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...?

  • @solvinglife6658
    @solvinglife6658 2 года назад

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

  • @aneeshahamed2490
    @aneeshahamed2490 3 года назад +1

    thanks bro🙏

  • @elpirato5428
    @elpirato5428 4 года назад +1

    muchas gracias!

  • @marcodeheza5981
    @marcodeheza5981 4 года назад +1

    Thank! Is working OK

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

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

  • @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 ruclips.net/video/CTvzoVtKoJ8/видео.html

    • @tothepoint1560
      @tothepoint1560 2 года назад

      Same problems i am facing.

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

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

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

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

  • @helenh2442
    @helenh2442 4 года назад

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

  • @jigneshraval6880
    @jigneshraval6880 4 года назад +1

    nice sir

  • @suhailzack9075
    @suhailzack9075 3 года назад

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

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

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

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

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

  • @ahsansyed4146
    @ahsansyed4146 4 года назад +1

    thanks buddy :)

    • @mafiacodes
      @mafiacodes  4 года назад +1

      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.

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

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

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

  • @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 RUclips settings. I guess that would work.

    • @nelsonmunthe4571
      @nelsonmunthe4571 4 года назад

      Still same bro, subtitle still nothing

  • @AbhinavBhaartiya
    @AbhinavBhaartiya 3 года назад

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

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

  • @moazelsawaf2000
    @moazelsawaf2000 4 года назад +1

    Thanks a lot sir

    • @mafiacodes
      @mafiacodes  4 года назад

      Subscribe like share 😊

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

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

  • @7days280
    @7days280 4 года назад

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

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

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

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

  • @ranggasuryaprayoga5997
    @ranggasuryaprayoga5997 2 года назад +1

    Thank you very much sir

  • @clips2613
    @clips2613 2 года назад +1

    Thank you so much!