How to fetch data from the Firebase Realtime database. Android studio Kotlin.

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys and welcome back I'm awesome and you are watching to the new video of the mko developer Channel this is the third video of the Firebase real-time database in the past videos I showed you how to send the data into the Firebase console we have created this Library we named it contact here and we passed three items here uh the name of the items is a random ID that we have created here by this line of code and then we created the child which is this and we set the value which was the contact and it's here the name and the phone and we took it from the user in the add fragment so if I open one of them you will see still we have the data the ID is in the first line the name and the phone number now in this video we want to take this whole data and display them in a recycler View uh in the home fragrance so if you are ready let's get started but before that if you are new in my Channel please hit the Bell and the Subscribe button to be aware about the new videos thank you okay in the last video I showed you uh how to change this uh labels based on the fragment that we are inside it and you see that it's changing but uh the text is not satisfying so uh I use this three line of code to do this and now Inside the Mind app you will see the labels here so I'm going to change them and just like this okay now I have home and add here yeah okay uh let's go third I don't need this and that's fragmentors so I don't need uh main activity I don't need this one as well and add fragments okay I'm going to add the recycler view here okay uh now I'm going to go to the resource manager to the layout create a new layout and I'm going to call it uh RV stand for Recycler View uh item or maybe let's write every context item okay and I'm going to speed up the video and I will Design this layout then I will back I will be back to uh explain the rest okay we are done with the layout I have a card view here in the center and a constraint layout three text views if you want to copy the text feel free to pause the video and write them let's go to the uh project and here I am going to create new package call it adapter inside it I need a particulars as the RV are we contact adapter okay here is the adapter class and I'm going to write the codes if you don't know how to work with the recycler View you can click on this link and watch the full course about the recycler View I am going to implement the members here and as we use the viewbinding in the rest of the parts so here also I'm going to use the view binding as well okay in the class view holder this is the extent recycler view again uh here I'm going to add binding equals to RB uh this one RV contacts item binding which is uh a class created automatically by the Frontline based on the name of the XML file the layout of this recycler View okay here and uh here I'm going to write binding Dot root okay should be private and here in the oncreate view holder I have to write return [Music] to the view holder class RV item binding dot inflate and here layers inflator from parent Dot context and here again parent and false okay I think we have one extra pound to this year now yeah this one is yeah that's okay and get item count here I'm going to private contact list and it is the array list based on the contacts glass the data class that you have created here to store the data inside and that's it here in the get item count beta and take list Dot site okay then here I am going to create the value solid current item and equals to contact list and I'm passing the position into this and then all there dot apply and then binding Dot apply I have another here okay make binding public yeah and then I have the text views here uh and I should write the data to store data inside them so first of all TV name item and the text equals to current item dot name and the same for the rest instead of the name should be phone [Music] and phone number here instead of the name ID and here right uh sorry about the voice the bad voice that I have and also uh low energy because I was sick for uh last 10 days and now I'm in a recovery so I don't have the energy that always I had sorry okay let's go further uh we are done here in the recycler view adapter and now let's go to the home fragment to write the code to retrieve the data fetch the data from the real-time database and then we will pass them here uh to be shown in the recycler okay if you are in the home fragment now uh we have created this view binding and everything and we used certain click listener for The Floating Action button to go to the ad fragment and now here we have to write the code to paste the data here I need private late in its variable contacts at least and it is arraylist on the contact and then private late in its variable Firebase reference database reference now here we have to initialize them first first like equals to Firebase database dot get instance the get reference and we passed the name of the library as the contact and here also we should write the same name then I have to initialize the contact list equals to daily stuff and then we are going to paste the data for this I'm going to create this function and here we need to write the Firebase reference Dot add value event listener then object column and value event listen [Music] click on the object and Implement members both of them okay in the one cancel I'm going to write a toast message and and on data change we need to store the data into the contact list so first I'm going to clear it if we have some data inside it then I will check if the snapshot dot exist then for foreign [Music] Dot children and well contacts equals to contact and snap dot get value here contact two columns glass dot Java and here uh contacts list Dot add and I'm going to pass this contact value into this [Music] if it's not empty okay uh here first of all we are checking if this snapshot has a value and then for all of the items that are inside this snapshot one by one we are creating this uh value and extracting the data from this get value and we are putting them into the scales and one by one we are putting them inside this contact list and then uh here [Music] recyclerview adapter equals to RV contacts adapter and we are passing the contact list inside this and here let me write binding Dot recyclerview contacts that apply and now that has fixed size the true and layout manager equals to linear layout manager and I'm going fast restart and text into this now the recycler view here is initialized and we can use it here so are we uh sorry binding dot RV contact Dot add that there equals to RB adapter which you have created here a moment ago this is the everything for the home fragment and now uh let's check it so we have the data here I'm going to [Music] install the app on the emulator let me open all of them we have one empty uh child here the name Julia with the phone number and the name Max with the phone number uh after installation we have to we should be able to see them here in the recycling okay it's done we have the Max and the empty and the Julia I'm going to write my name here and a random number has the phone number send data here is the data okay and I'm going back and you will see my name here as well so uh that was everything about this video in the next video I will show you how to click on the items and we will be going to a new fragment which is the update fragment and we will update the data that we are stored in each of these child be with me in the next videos to finish this tutorial together uh thank you for your time if you haven't subscribed the Channel Please Subscribe the channel and hit the Bell button to be aware about the new videos and also give me a thumbs up to help this video be watched by more people thank you bye
Info
Channel: MkrDeveloper
Views: 3,960
Rating: undefined out of 5
Keywords: how to fetch data from the firebase android studio kotlin, firebase to recyclerview, fetch data from firebase and display in recyclerview kotlin, how to retrieve data from firebase android kotlin, fetching data from firebase kotlin, firebase realtime database, firebase tutorial, firebase kotlin android studio, android studio tutorial, MkrDeveloper, mohsen mashkour, android studio, realtime database firebase, navigation component, retrieve data from firebase to recyclerview kotlin
Id: GZnCHLEo6ng
Channel Id: undefined
Length: 24min 11sec (1451 seconds)
Published: Tue Mar 28 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.