Retrieve Data From Firebase Realtime Database in RecyclerView (Android Studio 2020) #androidstudio

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hey dear welcome back to coding stuff and in the last tutorial we have successfully saved users data into firebase real-time database and in this tutorial we'll be retrieving the data and will display in the recycler view so i will be creating application like this if i click on show data you can see the same data over here is displaying on our recycler view and we have used cardio to display each user's data so one thing so this much of code is enough to retrieve the data from firebase real-time database but i wanted to show you how you can retrieve the data and you can display it in the recycler view and can use the cardview to display each user's data so recycle reviews little bit tricky for the first time but as you practice you get better at it so let's fire up our understudio and start creating the project add some data here so i'll write name as sam let's put any dummy surname and then click on submit you can see the data has been added sam jobs and the mail but uh there is one problem uh user doesn't know the data is uploaded or not data is saved or not he's not getting any notification or he's not seeing any tools so we'll do that now just a little bit of modification so after this set value we can add here on complete listener so add add on complete listener and he will pass new on complete listener and over here we'll just display one toast data saved that's it okay so i will show you that later so at the first we'll just add one button here and i'll constraint it and we'll set the text as the show data and the width will be match constraint and we'll add background color here some background and this will be color primary cool and we can also provide here margin horizontal of 20 db so margin horizontal of 20 db okay cool and we'll set id okay it is button too so just collect it button to and we'll add only listener to that button so okay so after this um we'll write here button two dot set on click listener new on click list now and here we'll just start the new activity so start activity new intent i will pass context as main activity.this and then show activity will create it in a minute so show activity dot class that's it okay so now we'll click on this pro okay so i will click on this java first package name and new new activity will select empty activity and i will name it as a show activity hit enter this error has been fixed so over here we'll just download the recycler view dependency so i have downloaded already just click on the download icon over here and i will drag it here we'll set the width and height as a match constraints and will provide the id recyclerview cool and now we create a layout for our each item to display so layout resource file i'll name it as item and will select card view instead of constant layers so card you and click ok and i will press alt ctrl l here to format this code and instead of this match parent height will provide here 1 1 0 dp and card elevation card elevation would be let's say 8 db and card corner radius will be 10 db cool we'll provide some margin of 10 db our first provide padding of 10 dp and also margin as a 10 db cool so now inside this will add one linear layout so linear layout it will be match parent and the height will be also let's wrap content and this orientation of this layout will be vertical and inside this will again uh create one linear layout so match parent wrap content and its orientation will be horizontal and inside this will add two textures so text view tribe content wrap content and it said text as email and then the text style will be pulled and then the text size uh let's set 20 sp cool and then we'll just copy this text view and we'll paste it over here so instead of 20sp we'll write here let's say 18xp 17sp maybe and let's write any dummy email for now so dummy under gmail.com so i have to provide some margin to this from the start so layout margin start and we'll write here 20 db cool and we'll provide the id to this texture and this will be email text cool and over here we'll just uh include one space and colon okay so now we can just copy this linear layer two times okay so cool so this will be lesser name and instead of email id it will be named text this will be surnamed and this will be surname text let's provide padding of 20 db so let's provide some padding to the through this text of let's say padding of 5 db cool to this also so padding uh 5dp and this one also so padding of 5dp so looks cool now so now for the moment we'll just close this and in our activity show we have drag to recycle you so in that show activity we'll just collect the idea of recyclerview so private recyclerview let's name it as recyclerview and we'll find its id so recyclerview equals to find your id r dot id dot recyclerview and then you apply some properties so recyclable so set has fixed size this will be true and in the recycler view dot set line layout manager this will be new linear layout manager and we'll pass the context so this and we'll copy some code from here you know from our main activity this one the instance and the reference so control c and i will paste it here okay so we are implementing recycler view so we need one model class and one adapter class for that we'll create first a model class so i'll click on the package name new java class and you'll write model and we have three types of data so string email name surname that's it and we have to just uh create gators here so click on generate and get us select all click on ok that's it for model class and now we can create adapter class so click on new java class let's name it as my adapter this will extend to recyclerview start adapter and inside this will write public will create another inner class so public static class named as my view holder and this will extends to the cycle of view dot view holder and we'll click alt enter here to input uh to create the matching constructor and we have to pass some generics here so this will be my viewfolder class that's it now i'll click on alt enter here and it will ask to implement some method so we'll click on ok that's it so over here we have to create an arraylist so arraylist and we'll pass your model class model and let's name it as the m list that's it and also we can write here context context and we'll create one constructor so public my adapter and will pass your context context and the array list of type model and let's name it as i am list so this dot and list equals to m list and this dot context equals to context and in oncreateviewholder we'll just delete this return now and we'll create your view so view v equals to layout inflator dot from will pass your context dot inflate and the layout so i dot layout dot item and in the parent as a view group and then the false attached to it and we have to return this so return new my view holder and inside this will pass v okay that's it for my view holder and in the gate item count we'll write m list dot size and inside this inner class we can define our textures so over here we write text view we have name surname email that's it now we'll find their ids so name equals to find you uh we have to use this item view so item view dot find your id i dot id dot name text and then we have surname so surname equals to item item view dot find your id sorry find your id and r dot id dot uh surname text and then we have the email so email equals to item view dot find viewer id r dot id dot email text okay that's it now we just have to uh implement this on bind view holder which is important so we'll create instance of our model class so model let's name it as model and we'll get the item from our m list so m list dot get and will pass your position then the folder dot name dot set text and here we can pass model dot get name and then we have holder dot surname dot set text model dot gets the name and then the holder dot email dot set text dot model dot get email okay so that's it for the adapter class now we can move to move to the show activity class and here we'll write some code first of all we'll create instance of our my adapter class so private my adapter name it as adapter and inside the oncreate we will just initialize this so adapter equals to new my adapter and here we have to pass the context and the list so we have not created the list till yet so we'll create it now so private array list and model and we'll name it as a list we have to initialize it also so list equals to new array list and here we'll pass our list cool so now we can set this adapter to a recycler view so recyclerview dot set adapter and here we'll pass adapter let me add some spaces down here so we'll use this root so ctrl c root dot add value event listener okay so instead of add valuement list we can also use add child image listener let me show you so we want to get data from this user node and we want iterate through this uh through this values so these are the values if we have inside this user another child let's name it as zero and it has this data then we have to use add child event listener we'll be using that in upcoming videos so at that time it will make sense so for now we'll just use uh this add wall value event list now so inside this new value event list now and we'll just put a semi column here and you can use here of for each loop so we'll use for data snapshot data snapshot till snapshot dot get children and then we create instance of model so model model equals to data snapshot dot get value and inside this will pass the model class so model dot class and it will set all the values to our model class and below this will write list dot add the model that's it and after this we can just uh we can just write our adapter sorry after this we'll write adapter dot notify data set change so that's it i think we have done everything fine so we can click on this run button now and we'll check our app is working or not okay so we have to move it little bit down so we'll do it in a minute so if i click on this show data you can see all the data has been retrieved from the firebase real-time database let me show you the last that is sam jobs uh you can see it sam jobs sam and jobs and then the jpgs okay then the elon musk okay so everything is working fine you can see and if i add any random data here let's write anything and i just wanted to show you that uh after clicking on submit button it will show us the tools that is data saved okay and again if i click on the show data data has been loaded here i think i have clicked two times okay so it's working fine we are successfully retrieve the data from firebase real-time database with one thing we can do also we can just delete this for a moment so now if i click on this run button so it is looking fine now so if i click on show data it is retrieving the all the data from all firebase real-time database and make sure your internet connection is on because uh if it's if it if your internet connection is not on then it will not load the data okay so in the next video we'll see how we can upload images to the firebase storage and how we can retrieve them using real-time database so do subscribe and save this playlist thank you for watching
Info
Channel: CodingSTUFF
Views: 19,186
Rating: undefined out of 5
Keywords: android studio coding tutorial, android studio coding for beginners, android studio coding in flow, android studio coding with harry, android studio coding tutorial hindi, android studio coding with mitch, android studio coding for login page, android studio coding pdf, belajar coding android studio, android studio coding cafe, cara coding android studio, navigation drawer android studio coding in flow, android studio coding for calculator, coding in flow android studio
Id: V4E5ROnbrGk
Channel Id: undefined
Length: 19min 2sec (1142 seconds)
Published: Tue Oct 20 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.