High students in this year Tauriel you're going to go ahead and create another Android app.
So just click on this.
Start any Android studio project and for the application name just say in here.
Sixty seven and you can specify the company domain package name and the project location here.
So now click next and he'll choose API 16 Android 4.1 Jelly Bean for the minimum SDK and then click
on next.
And he had to empty activity next.
And here don't change anything.
As you can see here just leave things as default.
And then he can finish.
So now let's connect our application to the firebase.
So at the top just click on Tools and then click on firebase and here click on real time database and
then click on Save and retrieve data.
First of all just click on this or connected to firebase.
And here this time we don't want to create a new firebase project here.
We want to actually select an already created Project right so choose an existing firebase or a Google
project search.
Make sure to actually take this radio button.
And here we want to actually connect our application to the app sixty eight tests one firebase project.
So here because you don't have app sixty eight tests one just select app sixty five.
Is that right.
Select app 65 and then click on Connect to firebase And now as you can see here it says Fire is project
created and connected locally to migrate app.
And here it says connected.
So now we need to actually Connelly's at the real time database to your app.
So just click on it and then click on accept changes.
So now our our product is actually ready.
So first we want to use actually an other feature of firebase which is called firebase.
So first we need to actually to get that dependency from the Internet.
So analysts actually open our Web browser here.
So as you can see here this is my firebase.
So firebase that Google does come and here click on go to console.
We actually connected our application to this project at sixty eight test one.
So now I just need to click on this database here and now we should wait and you can see these objects
here.
So you are already familiar with these objects.
We created these objects in the previous Oriol in the previous application and we sent this data to
the server.
So now let's actually just open another tab here right.
And here as you can see you just need to enter this you r l here.
I'll get hop dot com slash firebase slash firebase you dash Android.
Make sure to actually enter this you aren't here.
And then you will be guided to this page here.
Right.
And if you scroll down here as you can see of first of we need to actually put the dependency.
So here in here it says installation right.
As you can see here and here we need to actually copy this dependency which is for firebase database
only so here because we are interacting with the firebase database we need to copy this code here right.
If you need to copy this line of code.
So just as highlighted here and selected and just right click on it and then click on copy at the top
here it says in your app level beyond that great deal.
So let's go back to our Android studio and here as you can see here.
If it is actually the Android view here you just need to open this cradle scripts.
And here we have to build that cradle files.
The first one is the project level.
As you can see here and the second one is the build that built that cradle 5.
And it says means your app.
So we just need to double click on this one here.
And if you are using the departure level here you just need to click on these two little triangles and
then he had just click on this project.
And here if I open this folder here as you can see we have built that cradle here that is inside of
this project here and it is called the project level bill that cradle and we have this Apfel there and
we have also this build that cradle here.
Right.
So we need this app Libelle built that cradle.
So now let me actually double click on this one here and just have in order to make his area there and
here we need to actually paste that code inside this dependences Block.
And here at the top just click on scene now.
So now we successfully installed the firebase you are in database right.
So now let's actually go to our activity underlying main that examined and here is just selectees Hello
takes you and then I press on delete key on your keyboard.
So Linus actually tried a list view into this layout.
First of all at the bottom just click on this text tap here and now is actually the change this is relatively
out to linearly out right.
And now we should specify the orientation.
So before the end impact of this linearly out here just type in here all the Android orientation and
choose vertical.
And here at the bottom just click on design tab here.
So and its next to the center for the list view here as you can see we have these containers folder
and in so its container folder we have this list view here right.
Just select it and try and get here into this linearly out vertical.
And now heres select this a list view here.
And for the ID just type in here list view and then person here on your keyboard now we have this list
view.
Let's go back to our main activity the java file here and our First of all we need to actually create
a class actually a box at a class.
Right.
So now are here that this actually change this project view to Android view.
So really this little triangle here and then click on Android.
And now as you can see inside this app for live inside is a that we have this package just a selected
spec each year.
And at the top or click on File New and then click on Java class and for the name of your class.
Step in here Boxer and here don't change anything.
And click on.
OK.
And now double click on this tab here box set The Java.
And now inside this box of a class let's actually create some instance variables so I can say private
strange Buxar name right semicolon private and punch power semicolon probates and Ponch speed semicolon.
So now let me show you the web browser here.
And because we actually connected our application to the to this project absence the eight tests one
of as you can see this is the boxer named punch power and punch speed.
So we have these instance variables here.
Right.
So now as I told you because you want to actually interact with the firebase database first here because
this is a class that we are going to create objects and we are going to send the objects that are created
from this class to the firebase we need to actually create an empty constructor here first.
So here I can just type in here public.
So the access modifier of my constructor is public and the name of the constructor must be the same
as the name of the class.
And then I need to put a pair of parenthesis here and then I just need to open and close.
These are constructed by using these curly braces and opening curly brace followed by a closing curly
brace.
And now let's actually create another constructor in order to initialize these instance variables.
So here I can just right click on that.
Inside this class and in here I can click on generate and click on constructor and select all these
instance variables and then click on OK.
So now as you can see here the Andrys pseudo-ID generated a constructor for us automatically.
So now we need to actually create get here for for instance valuable well so as you can see here the
access modifier of these instance variable variables is actually private.
So we need to provide getters here in order to allow other classes to access the value of these instance
variables.
So here I can just right click here and then click on generate and then click on get here and here select
all these instance variables and then click on OK.
So here we have these getters here.
So let's go back to our main activity that are filed here.
And first of all of any to actually declare inside this main activity class we need to declare our list
view valuable so list view and the name of this valuable is list view.
So in so it is uncreate me effectless actually initialize this list.
So here I can see list view.
Assignment operator and I need to cast this object to have a list view object find view by ID or ID
that list view.
So we call them so now because we want to interact with the firebase database so when we need to actually
declare some variables here inside this man to class the first variable is firebase database and the
name of a database semicolon.
And the second variable is database reference and the name is then the name of this variable is database
reference semicolon.
And inside this uncreate method I also want to actually enable the offline capability.
So here I can say failure rates database does get instance that said persistence enabled.
True.
So and then we need to actually just listen to initialize our variables for database assignment operator
and here I can say Firebrace database that get instance semicolon and actually initialize our database
reference database reference assignment operator.
And here I can say database that gets the reference semicolon on here and just a database reference
does keep seemed true.
So in this way we actually enabled the offline capability and we also initialized valuables the database
and the database reference.
So now we can actually interact with the firebase database.
So here are because we actually added the fireplace you are a database to our application.
We actually installed that dependency populate our list view feed the data that we actually receive
from the server.
So let's see how we can do that.
So if you remember from the previous section as of this course I told you that if you want to populate
your list view of that data up first you need to create an adapter so an adapter is going to actually
populate your view with that data.
Right.
That's the job of the adapter.
So because we want to actually get the data from the firebase database we need to actually create a
firebase list adapter.
Right.
So inside our main activity class let's actually declare a firebase list adapter variable so I can say
firebase least adapter.
Right.
Just select it and then press an interview on your keyboard.
And this class is actually inside the firebase.
You are the database that dependency that we installed up inside our application.
So firebase this adapter and then Aimee's firebase this adapter semi-colon.
Right.
And now let's actually go inside this uncreate method and this actually initialize our firebase list
that actor.
So here I just need to refer to the name of my valuable Firebrace this adapter assignment operator new
firebase list adapter.
So as you can see here just hold the shift key on your keyboard and then press on the letter F key on
your keyboard and then did the auto complete feature of the Android studio is going to help you to choose
this option.
Fire basically Siddartha.
And now as you can see here inside the curly braces we have dot dot dot.
Just select this option and then person enter key on your keyboard.
And now as you can see here the autocomplete feature of the Android studio is going to help you to actually
use these coats.
So as you can see here at the end of this curly brace we need to put a semi-colon on here.
As you can see it is when we actually created a new object a new instance of type firebase licit after
we need to actually provide some arguments.
So inside the Prentice's as you can see here we need to first of all specify the context the activity
and then we need to specify the model and then we need to specify the model layout.
And finally if you need to specify the reference.
So let's actually go inside the curly inside Apprentice's of this constructor as you can see here and
now.
So for the first argument I can say main activity that is.
So this is the context the semicolon and the second argument is going to be the model class.
So the model that we actually want to use is the Boxer class as you can see here.
If you're if I show you the web browser here as you can see if you have lots of box set objects as you
can see here these are parts that objects and began to populate our list view of the box of objects.
So the model class is going to be.
So let's go to and listen so you and go to main activity the Java the model class is the box art class.
So just they've been here.
Boxer dart class right.
Come on.
And for the first argument we need to specify the layout.
So now let me actually create a new line here.
So for the first argument of you need to specify the layout so the layout layout is Android Android
dogs are taught lay out that simple list IDM Vaughan select this one here and comma and finally you
need to specify the database reference.
So here I just need to type in database reference.
So these are the arguments that we need to specify here.
If you want to actually populate my list with the data from the server we need to actually specify these
arguments.
And now as you can see here we have this Smurfit right populate view.
So let's actually go inside the curly braces of the Smurfette And now here I can just say.
So first of all as you can see this method populates you actually accepts free arguments the first argument
is actually of type view.
Right.
And the name of this argument is v.
So we can get you to change this name to view right.
And the second argument is actually of the hype object and the name is modeled.
So this uptakes is going to be the object that we receive from the server.
I mean but at the box it objects.
And here we have this position.
So this position is going to specify the position of our object in say the least.
View for example our first object is going to be inside the position 0 or our second object it be inside
the position number 1.
So here inside the Smurfette I can actually say let's actually put a pair of Prentice's here and now
I can actually cast this view.
So as you can see here this view is actually they view the cell that specific cell that we have inside
the list view.
So now let me show you the activity underlying minute example.
So for example we have this item Vonne here.
We have asked him to or we have.
Item 3 this item 1 is actually of view this item do is view this item free is our view.
Right.
So now when I say view I mean one of these cells one of these of actually the items.
So main activity that of up and here listen to the chest.
One of these items or views to our hexed view.
Right.
So inside Apprentice's just put another practices here another pair of practices and here just typing
text view takes you.
And here I am actually casting this view to actually a taste.
You're right.
And here I can see a view but find view by ID.
So now I am saying that view that's fine by you I'm going to go inside this item right inside the cell
or inside this item.
It is actually called a view right.
And I want to get this item one text right.
Not the sub template.
I want to actually get this item on text so now I can say view that fine view by ID or dot ID dot text
one right.
Or that I did a text one.
So it's better to put the android that are that ID that text one because this takes one is actually
inside the Android package.
So Android that are that Id dot text one.
And here we have this actually text view.
And here I can say as you can see I actually cast this object to a text view object.
So here after the end prentices I can't say that said text.
So here we received the box that object he had as the model right.
So here I can say model that gets as you can see here.
Now want to actually for example get the Buxar name right.
So let me show you the web browser as you can see if you have a name named punch power and punch speed.
And this model this object is actually the optic that we receive from the server.
So how come that we cannot actually access the box or name because we are not specific enough to access
that box that object.
You are just saying that object.
Right.
But as I told you in the Java section of the Course all classes in Java are actually a subclass of the
object class.
Right.
For example here we have this box of class right.
This box of class is actually a subclass of the object class.
So inside is an activity class we can't just say model that get boxer named because this object is actually
the superclass of the boxer.
Right.
So I mean now we need to be a little bit more specific we need to specify that the object that we are
getting from the server is actually a box that object.
This is really important.
So how we can do that.
First of all let's scroll to the top here.
As you can see when I actually declared this rowdier firebase that after here after the name of this
class here I can put a pair of angle brackets here as you can see and here I can't say Buxar right.
So in this way I am saying that the object that we want to get from the server is going to be of type
box class.
And if you scroll down here now as you can see less actually change as you can see we have the right
literature to change this object to Boxer.
And here we have this letter.
Right.
It says that class and NMC class did died from a fire baseless after must either be declared abstract
or implement abstract Meffert populate view.
Right.
So now let's actually after the name of this class new firebase listed after here you can actually put
a pair of angle brackets.
And here you can see Buxar.
And now as you can see here the error is gone.
Right.
And here I can see a model that gets Boxtel name.
So in this way we don't get any errors.
And as you can see here I just put a pair of angle brackets after the name of this class.
So new fighter basically said after an inside the angle brackets I specified that the object that that
you are going to receive from the server is going to be of type Buxar class not object boxer right.
And here we actually specify the arguments and now we actually have this populist view.
So this populates buma if it accepts free arguments the first one is the view.
So I told you that the view is one of these cells.
Right.
And it bugs that object.
So this is the model.
This is the data that we want to receive from the server and populate our view with those data objects.
And here we have this position the position of an uptick in say the list view.
Right.
And here inside the populates you Smurfette are first of all of actually cast that we actually created
an object.
For example we are actually referring to the text 1.
So now let me show you the activity underlayment example.
So this takes one.
Here is this.
Item 1 for example or this item 2.
So when I say text 1 I am referring to that specific text.
So we all view refers to that cell to that view that find you this is going to go inside that view and
it's going to find a view or a text view actually inside that view.
And here or so I told you that takes you is actually a subclass of view.
So this means that takes few is actually of view right.
And that's why it says find view by ID.
And inside the apprentice's I am referring to the text on Android that are the ID that takes one.
So this takes one here is actually already created for us.
Right.
And here after the end prentices I am saying that Datsik text I am referring inside the Prentice's I
am referring to this model which is Buxar object of Buxar class model that get Poch surname.
So in this way we can actually get the box uname and we can get the Pogson name of each object of that
we have inside the server.
As you can see here we can get a box in name of each object and we can populate of our list view with
that specific box name.
So let's actually run our project and see what happens.
So now as you can see here our application is actually running on the simulator and TV can not see that
data.
We cannot see the data that we receive from the server and we cannot see that list view.
So let's solve this problem.
So we actually forgot to do something very important right after using the adapter after populating
our view with the boxer name right after these lines of code.
We need to say that as you can see if we have firebase list it after what I told you did fire up baseless
adapter is going to actually populate our list view.
We did.
They thought that we receive from the server.
Right.
So now we need to actually connect our list adapter our firebase adapter to our list view.
And that's why we cannot see up the list.
We cannot see the list that is populated with the data from the server.
So how we can actually connect our list view of it fire basically said Apter.
So here I can say after the end Incra liberal brace of this adapter and before the curly brace of the
Smurfette uncreate Mefford Enceladus uncreate create Meffert I can't say list view that set adapter
firebase Lisa adapter so this is very important.
This line of code here is really important and if I run my project here let's see what happens.
Let me show you.
As you can see our application crashed.
Right.
So now we need to actually debug our application our application has a park.
So I told you that you need to go to the Android studio and at the bottom you just need to click on
this android monitor.
Right.
And now that let me make this area wider.
And I told you you have to actually look at the fatal exception here and here it says Jarba that land
at runtime exception unable to start activity component in info.
And this is actually scroll to the right and it says conduct Google that firebase that database that
database exception calls to set persistence enabled must be made before any other usage of firebase
database instance.
So now let's actually go to our Android studio.
Let's look at these lines of code here.
So this error again is actually related to the Smurfette said persistence in a belt.
And as you can see first we actually are declared art valuable insight is an activity class firebase
database database.
So it says that of first this line of code here is going to be executed before any other usage of firebase
database instance.
So let's actually are in-line number 18 as you can see when we actually declared our firebase database
here.
Let's actually did it this line of code here and here let's go inside this uncreate Mefford and here.
And before this database I can say firebase database so this means that are actually creating this instance
here.
So let's run our project again.
So now as you can see here our application is actually running on the simulator and we are actually
successfully receiving this data from the server.
So now let me show you the web browser as you can see here.
These are the data that we are receiving from the Sarette.
These are the box set objects right.
And here we can see that we are getting the name of the box at Potulny.
So the first one is a the second box it is B again the first box it is be and you can see the box and
then here again is.
So we are receiving this data from the server and we are actually populating our list view of the data
that we receive from the server.
So this is how we can actually populate your view of that box that objects that you receive from the
server.
So for example I want to actually also get the punch power and the punch speed.
So let's go to Android studio.
And now we can actually as you can see we have this adapter right.
And when we are actually initializing our adapter as you can see here we specified the layout right.
Android that are that out that simple list item 1.
So we can get you to change the layout.
So this actually did it this way out.
And here I can't say Android that are that the layout got to line list item right.
To this I lay out in that line this idea and now here we can actually say it takes you view that's fine
view by the Android that are that ideal that takes one that said hexed model that does get Boxer name
and he had inside Apprentice's I can actually use a plus operator.
And then here I can say I can put two double quotes right.
I can actually put a dash right.
So let me actually the appropriate space.
And after two after these double quotes I can actually put another plus the operator.
And here again I can't say model that get a punch power plus.
And then again if I can put two double quotes dash plus model that get punch speed.
So in this way we can actually also output these values to the screen.
So let me actually create a new line here and now you can see this when you hear better.
So we have a text view as you can see and we are setting the text.
And here we are same but model that kickboxer named dash model that gives punch power dash models that
get punch speed.
So let's run our project now.
So I remember that first we actually change the tele out and then we actually put these other values
here.
Right.
So let's run our project again.
So now as you can see here I actually got the data from the server.
Right.
And now we can see this data a 100 200.
So now let me show you the web browser and let me show you the emulator for example.
This is the box and aim is a punch power it's 108.
And the punch speed is 200.
So this is how he can actually work with the firebase list adapter.
And this is how he can populate this view with the data that you can actually receive from the server.
Right.
So these are the data.
So I think that's enough for this Tauriel.
So if you have any questions please post the discussion in the course and then I'll do my best to answer
all of your questions.
Thank you very much for watching and I'll see you in the next year or two earlier.