And now let's actually delete this line of code here.
And now let's actually create a listener for the spot in and send data on the server.
So just step in here PTEN send data to a server that sits on click listener.
OK new.
And then here just hold the shift key on your keyboard and then press on the little Vicci on your keyboard.
And now as you can see here the autocomplete feature of the Android studio is helping us to choose this
option unclick listener.
And now as you can see here inside the curly braces you can see this value dot dot dot.
So choose this value and that person entered key on your keyboard.
And now as you can see here these lines of code here are automatically put here by the Android studio.
So here we have actually an anonymous in a class that actually implements this unclick listener interface.
And because that anonymous in a class is actually implementing this unclick listener interface that
class must provide an implementation for this Smurfit uncle.
So now we are actually inside an anonymous inner class so here for example I can actually just typing
database reference dot child.
So now I can specify the child.
And now I can actually just get the value of this as it takes it.
EDT keep.
So here we are going to specify the key.
Right.
So EDT key dot get text dot to a string.
Right.
And now I can say Dot said while you and here for the value you can put the value of these text it is
de-value right.
So EDT value that get tix to string.
And then I can put a semicolon at the end of my statement.
So as you can see here again let me actually just explain again.
Actually we have this database reference that is referring to this instance as you can see here to this
database instance.
Now let me actually did it this value here.
So here we have actually our reference database reference that is referring to this instance inside
our database.
Right.
And now we say that tight.
So here we want to actually create a child for this instance and the tide value is going to be key that
takes that to history.
And then we are going to actually call this method and that tight set value.
So then we can actually specify the values the value that takes that to history.
So now let's run our project and see what happens.
Now let me actually open the web browser.
Now let me show you the emulator here.
So here let me specify the key so that you can be for example up more by name and the value can be phone.
IPhone 7 right.
And here let's actually click on this button send data to a server.
And now here inside this database you can see that we have actually a child.
And the key is mobility lane and the value is iPhone 7 right.
So hopefully that makes sense.
And now I want to show you something really important.
So let's go back to what Android studio and here I can actually create are random actually unique ID
for my keys.
Right.
So as you can see this is the key and this is the value.
I can actually create a random ID for my keys so that there will be different keys for different values.
So let me actually show you that here.
So in order to create a random ID here first of all we need to actually create a variable of types think
so.
So it is unclear if I have actually just they've been.
And the name of this variable can be for example unique ID and then I put an assignment operator here
and then I'll refer to that to this database reference.
So remember this database reference here actually holds the reference as you can see here.
This database reference holds the reference to this database instance as you can see here.
Right.
So now here I am referring to this database reference dot dot.
And here I can see push right push.
When I actually call this push method and this reference is going to actually create our Random unique
ID inside its database reference and it's going to be as a key that unique ID is going to be as a key
right.
And here in order to assign that unique ID to this variable unique ID here and say Dot get key right.
And then I need to put a semicolon at the end of my statement.
And now let's see how we can actually create a child with that unique ID.
So in order to do that.
So now let me actually just make this area disappeared and now I can say just database reference dot
and here I can specify the child.
So remember when I say database reference this database reference here is actually holding the reference
to this instance.
So I need to create children for this instance and then I can actually provide values for this instance.
Right.
So first of all I need to specify the child so the database reference that child and the child is going
to be this unique ID write the child.
Right.
So you can say unique ID dot set value.
And then here I can specify the value so the value can be a string value.
And here I can say that this is of value and then I can put a semi-colon at the end of my statement.
So now let's run our project and see what happens.
So now as you can see here our press is actually running.
So let me show you with the attitude of a browser and this is my emulator and here as you can see for
the key I put this more by name an iPhone 7.
Right.
I can actually create other values so for the key which has actually just a computer name and for the
value I can say match with pro MacBook Pro and here let's actually click on this send data to server
and now it's going to actually create a new value here for me which is this one computer named Mike
Rowe and it also created this value for me here.
As you can see look at this key here.
This key is actually a unique ID that is created by the firebase for me right.
This key is not going to be similar to any other keys that are going to be created by the fireplace.
So this is completely unique.
And now we have actually a value right.
So you can actually make all this key actually as a category.
So lets see how we can do that.
Let's actually go back to our Android studio and now let's create another actually another unique ID
so we can say database reference.
And here I can say that push and here I can say that child write database reference that push that child.
So here let's actually specify the child so the child could be for example a child.
And here are each and specify another child.
So here this child is actually going to be the child of that unique ID.
Right.
I can specify another child.
So let's actually just set a value to this child and he'll say set value.
And then I put two double quotes here and and I can say what do you let's actually put a semicolon here
and now let's actually run our project and see what happens.
Now let me actually open my browser and this is my emulator.
So let's actually click on this button again here.
Send data to server and again as you can see here it actually created this unique idea here with disvalue.
So again because this is actually a unique ID different keys can be here can be put here with different
names right.
But at different times with the same name can not be put here.
So as you can see we have this key here and here we have this child which has this value.
So this key is actually playing the role of a category.
And inside this category we have this child and value.
So let's see how we can actually access the values of these are actually keys the values of these instances.
Right.
So for now we have these children and we have these values.
So how we can actually get these values from the database.
And now let's actually go back to our Java code.
Let's go back to our Android studio and now after the ending prentices of this listener for this PTEN
send data to a server here I'm going and going to actually create a listener for this button Betty and
get data from server.
So as you can see here if I show you the emulator we have this button gets data from server.
So let's actually create a listener for this spot.
So here I can say BATNA get data from server that set unclick listener.
And here I put the new keyboard.
And then here I hold the shift key on my keyboard and then personally there Vicci on your keyboard.
And now as you can see here the auto complete feature of Android studio is helping me to choose this
option.
Uncle Glassner and then choose it and then press on Enter key on your keyboard.
And now as you can see here the autocomplete feature on Android stood You helped me to actually just
put these lines of code here and now as you can see and as you know we have actually anonymous in a
class that is implementing these unclick listener interface and it is actually providing a implement
an implementation for this unclick method.
So inside this enclave nymphet we need to put the codes in order to get the values that we have inside
the database.
So let's see how we can do that.
So first of all we need to pro-white our listener.
So now let me show you the web browser first of all we need to provide a listener for these children
or for instance you can pro-white actually.
Actually it is called value Lessner right.
You can pro-white a value listener for each of these instances right.
For example for this instance we can provide a listener for this one for this one or for any others.
So let's go back to our Android studio.
And now first of all for example I want to get the value of this keep right.
I want to get the value of this key.
So let's go back to our Android studio.
So here I need to actually get our reference to this key.
So if I click on this key here as you can see this actually you are right here is changed.
Right.
So it is called.
Now we have actually a different you all.
So first of all we need to access this key we need to get this key.
So let me ask you to click on this one here and I going to show me the whole database here.
So now I'm going to pro-white a listener are valueless in their 40s key.
Right.
So let's go back to what Android studio and now we need to actually get our defense to our firebase
database.
So if I scroll to the top here as you can see in line number two in eight we actually created just a
variable which is after firebase database that holds the instance of the database that we are going
to want to get right.
So let's scroll down here and now I can here just say firebase database dot.
And here I can get the difference right.
Good defense.
So here I want to get that there.
Get the reference right.
So I want to actually change the reference because let's say go to the just google crowd here to our
Web browser as you can see.
You want to get.
Let's let's see the whole database.
You want to get the value of this key right.
That's the goal here.
Right.
So now all you need to have are reference to this key.
So how we can do that in order to do that.
First of all we need to actually refer to our firebase database instance.
If I scroll to the top here as you can see inside this uncreate it in line number twenty eight we have
actually an instance of type firebase database.
Right.
And now we want to actually change the reference to this key.
This key here right because I want to get this value.
So here I can say firebase database but get reference as you can see here.
So we have free Moffats get reference with actually an argument of types 3 and a get to without arguments
and gets a reference from Dorel.
Let's choose this one get reference here that accepts one argument of types 3 and.
And now I need to specify the argument.
Right.
So the argument is these key right.
As you can see here because you want to get the reference to Diski here.
So just highlight this key here and right click on it and then just click on copy and let's go back
to our Android studio and instead of double quotes put this value.
And now I can call this Mefford dot at add value event listeners so we need to actually provide a listener
for this key so that when the data is changed this class here is going to be notified.
So add value event listeners just press an interviewee on your keyboard as you can see here add value
into listener.
Now let me ask you to create a new line here so that you can see the value better thought Id value event
listener and inside Apprentice's.
I can't say new and then hold the shift key on your keyboard and then press and delay their key on your
keyboard.
And now just select this option here a value event listener and then press an Enter key on your keyboard.
And now as you can see here these lines of code are actually automatically put here and now as you can
see here we have an error and it says X expediter expect that a semicolon.
So just put a semi-colon at the end of this prentices and now the error is gone.
So if you have two Misfit's here the first one is on the path change.
So this method is going to be called vended data is actually changed and it is going to be called another
time.
For example when this actually Meffert is going to be called.
Right.
So when I actually click on the spot button PTEN get data from server.
This method is going to be called.
And also the data here is changed this method is also going to be called on data change.
So inside the curly braces of this agency you get this data and we have another MFL which is on canceled.
And this is called When that data is actually canceled.
So for example we want to get the data on the entire internet connection is actually gone.
So in that case we can't actually get that data.
And in that case this method is going to be called.
So inside this on day to change I can just say just create a string variable in order to hold the value
of this key stream.
And here I can say value assignment operator and here as you can see we have this argument.
So this argument holds this value.
The value is key because we actually provided a listener for this key.
Right.
So here I can say something about you assignment operator date snapshot data snapshot that get value
and then put a semicolon at the end of your statement.
And here we have an error and it says incompatible types required Java that line.
That's strange but it is found in Java that Langat object.
So let's go inside Apprentice's in order to specify specify that this value is actually a string value.
We can say three in which capital S that class.
And now the error is gone.
And here I can set this value to my take.
It takes you so it takes the value that text value.
Now let's run our project and see what happens.
So now let me actually to just open the web browser.
And now let me actually just open the emulator here.
Now the emulator is here and now let's click on this get data from server and now as you can see here
we successfully got this value.
This is of value right.
As you can see here disvalue is here for Diski.
So hopefully that makes sense.
And let's actually get the other values here for the other keys.