High students in this year all we're going to go ahead and create another Android application.
So just click on the start of your android studio project and then for the application name just a in
here at 69 and then here you can specify the company domain package name and project location and initially
connect and he has choose API 16 Android 4.1 Jelly Bean for a minimum SDK and then click Next on here
choose the activity next.
And here you can specify the activity name and lay out the names so just leave it as default and then
we can finish.
So here as you can see our project is created.
So now let's actually connect our application to the so it's at the top just click on Tools and then
click on firebase.
And now it's going to actually open the firebase assistant here for us.
And then here click on storage or click on our realtime database excuse me realtime database and then
we can save and retrieve data.
Did that here click on Connect to firebase.
So it's going to actually open the starting next day like for us.
So let's wait a little bit here and now I want to actually connect my application to an already created
Project in firebase.
So choose this option choose an existing firebase or Google project.
Just check this a radio button here and now select apps 65.
Right.
I want to actually connect my application to 65 and then click on Connect to firebase.
And now as you can see here it's this firebase product creators and connected locally to module app.
And we need to do the second step here at the realtime database to add up.
So just click on this button at the realtime database to your app.
And now we need to actually accept changes.
For just click on this button accept changes.
So it's going actually to something here.
So let's actually wait a little bit here and now as you can see here everything is ready.
So now let's actually go to our activity underlaid minute example here.
So let's actually delete this hello world takes you here and now it's actually inside this pallet section
this scroll down here.
And this actually drag on recycling you into into our project.
So here when I actually select this recycle view it can actually open the dialogue for us and it says
add project dependency and it says this operation requires the library recycle you receive it.
Would you like to add this library now.
Yes.
Just click on OK.
So it's going to actually add recycle of dependency to our application.
So it is very important.
Right.
So let's wait a little bit here and now as you can see here everything is ready.
So again I have this rendering problem.
So I told you in the previous tutorials in order to solve this problem you just literally can build
at the top.
And here you can either click on the project or rebuild project.
So this time I choose this one rebuild project.
So let's wait a little bit here.
And the difference between a clean project and the liberal project is that the clean project is going
to just clean your project and rebuild project is going to first clean your project and then it's going
to actually build your project right.
So it's much better to use the liberal project now as you can see where the errors are gone.
So now it's actually just at the top click on View and then through windows and then click on Project.
And now as you can see here we have this android view here.
Right.
So here at the bottom we have this great script so just open the screen.
Great telescopes here and now we have the build that great project.
So this is the project level builder cradle and we have the applet will build that great.
So this one level build that cradle.
And here we have these dependences block and here as you can see we have this right.
So again we have this same error and because I am using the AP I-24 here it actually puts the AP 25
right 25.
So change this 25 to 24.
If you are using the AP 24 so now let me show you the Android studio again.
So Android studio at the top just click on Android studio and then here click on preferences.
So if you are using a match you need to click on Android studio and then click on preferences and if
you are using a Windows machine you need to click on file and then click on preferences or settings.
So here just click on preferences and now I want to show you the assistant manager so here just opened
this appearance and behavior and then opened the system settings and now just click on this Android
SDK here and at the bottom click launch standalone SDK manager.
So it's going to actually open the Android as the case manager for us.
And as you can see here we have Android seven point one point one AP I-25 and we have Andrii 7.0.
So here are these calls we are using Android seven point zero.
So if you are using Android 7 point 1.1 API 25 no problem.
You can use API 25 or and here you can just actually naturally close the window.
You can just use that 25 right.
If you are using API 25 but here because I am using Android 7 API 24 I need to change the value to 24
right in order to solve this problem.
So this is very important.
And then at the top I need to click on scene now.
So now the problem is solved.
So here we need to actually add another dependency here and that dependency is firebase database UI.
This is very important.
So now that you actually open the web browser.
So as you can see here this is my web browser and I actually entered this you all get hopped at Camp
slash firebase slash firebase you Idas Android.
So now let me actually just as you can see here it says table of contents and installation.
So here we have this installation and now we need to actually add this dependency to our application
and it says firebase UI database only.
So just copy this code here right click on it and then click on copy and let's go to Android studio
and here it says this dependency to Apple will be that great.
Right.
So here these are applicable bill that graden And here we have these dependences block.
So just paste this cord here inside these dependencies plug plug into the scene now.
And now its going to try to synch our project.
And as you can see here at the bottom it says a refreshing firebase state so we should wait a little
bit here.
So now our project is ready.
So lets go to I underline minute example here.
Let me ask you the DoubleClick is stop in order to make this area wider.
Now as you can see first of all let's actually click on this activity underly I mean they seem at here
inside these componentry section it says Relatively out.
So at the bottom click on text tab here here and then change this relatively to linear layout.
Now we need to actually specify the orientation of our really linearly out.
So here just type in orientation and now the autocomplete feature of Android studio is going to help
you to choose this attribute Android called Call and orientation.
So and then press on into your keyboard and choose vertical and actually switch to design at the bottom.
Here let's actually as you can see if you have this custom for their app compact right.
This actually again tried this recycled view into our Linnea lay out where the card so here this is
our recycled review.
So they are selected and for the ID just type in here recycler you and then a and entity on your keyboard.
So now let's actually go to our main activity here and now first of we need to actually create some
valuables inside our domain with the class.
So here let's create a boxer class.
So now let me just at the top click on view to Windows and then click click on Project.
So here we have this app and then double click on the Starfall there and here just open this package
and select this package and then click on file at the top new file new and into the cantabile class
and for the name of our class just type in here.
Buxar identical.
OK.
So now we have this Buxar class and there isn't that I actually created these classes because of you
are actually receiving Buxar objects from the server.
So let me show you their web browser here.
So this is our Web browser.
And as you can see just click on go to concert at the top.
And here I need to click on app 65 so you know that we actually connected our Android application to
app 65 firebase project.
So just click on I-65 here and then here click on database.
So we should actually refresh the page in order to see this data.
We can actually just select rules and then click on data again.
Now as you can see we have these a box of objects here.
Right.
So let's go back to the studio.
And as you can see we have a box or a name box.
Punch power and punch speed.
So these are the instance variables of our boxer class.
So here I can't actually say private's screen box Boxer name semi-colon.
Private int punch power
semi-colon probably read in Punch speed punch speed semi-colon.
So now are we to actually create an empty constructor here.
So I just see it right here.
And then you can generate and then click on constructor and here just click on this package in order
to de-select all these instance variables and that really kind of.
So here we have this empty constructor and we have another we need to actually create another constructed
in order to initialize our instance variables.
So here I just right click on this in say this class boxer generate and then click on constructor and
just select all these instance variables and then click OK.
So here we have this constructor that is actually initializing all these instance variables.
So we need to actually create a getter methods in order to actually allow other classes to access the
value of this instance variables.
So as you can see here the access modifier of this instance variables is actually private.
So we need to provide getters for instance variables here.
So it actually can generate and then we can get here and then here select all these instance value events
and then click on OK.
So here we have these getters.
Right.
So now let's actually go to activity underlaid main and examine.
And here I want to actually create a custom layout for each item for each item view.
So let's see how we can do that.
So now at the top just click on View and then tool windows and then project.
Now Art just DoubleClick and the savez folder and then I will click and this layout for there just select
display for that.
And at the top click on File new.
And now we want to actually create a layer of three source file.
So just select this file here.
And for the name just type in here custom underline row.
So this is the name of our file and the root element is linear.
Lay out the source that is main and the directory name is layout and then click on OK.
So here we have this custom row.
Right.
And here inside this componentry section it says linearly Ellsworthy call if it is not linearly old
we can just click on it takes it up here at the bottom and here you can actually change for example
that the old name too linearly out and then remember that you must actually pro-white an attribute for
orientation of your linearly.
This is really important.
So now I just need to click on this design tab here at the bottom and here let's actually first of all
just selectees linearly out vertical here.
Or you can actually see at the bottom Picante step here at the bottom.
And here you can actually change the layout height to Lappe content.
Right.
Because this because this is actually going to be a custom roll we want to display height to be wrapped
content because this is going to be only our row not our layout.
And you can actually also change this attribute inside this design tab.
And here you can't change the layout height to lap content.
Right.
So the layout is much apparent and the layout height of our linearly alphabetically is that content.
And now let's actually tried a text view into this linearly as vertical.
So inside these widgets folder just selectees takes a view and then put it here inside is linearly outwards
the call all you can actually put it here inside this componentry section.
And you can put it inside this linearly or two vertical.
And let's actually isolate this text view.
And for the idea to step in here takes the boxer takes the box name and that person into on your keyboard
and let's write another text view into this linearly outway article.
So inside these widgets folder to select this text and put it here below this takes you.
And instead this linearly outwards.
Just select this takes you here and afford the idea to step in here takes the punch power takes the
punch power and then present energy on your keyboard.
Now let's actually try.
This takes you here to select the stakes and drag it here into this linearly I-30 can just select this
text and for the idea just step in here takes the punch speed and in person enter here on your keyboard.
So now let's actually go into our main activity that double file here and now let me actually double
click on the spine in order to make this area wider.
So inside this main activity class I'm going to paste in some lines of code and then I'm going to explain
to you what's going on here.
So as you can see these are the lines of code that I pasted here.
Nilay number 13 as you can see we have this variable.
I actually declare this valuable and the name of this valuable is database reference and the data type
of this valuable is database reference and the access modifier is private.
And here in line number 14 here we have this firebreak recycle or adapter which we get from the firebase
set up as you are.
And that's why we actually added that dependency to our application in order to use this class firebase
recycling adapter.
And here inside the angle brackets we need to specify two arguments the first argument is the type of
the data that we want we get from the set.
So the first one is the Boxer Boxer class and the second one is the view holder which is going to specify
the view holder of each item.
Right.
So we're going to create this view that last year.
And for now it is in red right.
Because we haven't we have we don't have this view that A-class inside our project and the name of this
variable is firebase recycle adapter a line number 15.
We have another variable and it's access but the file is private the data type of this variable is recycled
review and the name of this variable is recycling.
So inside this uncreate Smurfette I want to initialize these variables so I'm going to paste in some
lines of code here inside this uncreate method and then I'm going to explain to you what's going on
here.
So these are the lines of code that I pasted here.
And in line number 26 here I am really to this recycle view that I have declared in line number 17.
Right.
So here I want to initialize this variable so the cycle of you assignment operator and I am referring
to does a user interface component right.
Recycle have you find you by ID or that Id dot.
And as you can remember they recycle a view.
We actually name this ID as a recycler of your not recycle view as you can see here.
If I actually go to actually with the underline minute examine the idea of this recycle of is recycle
are you.
So let's go back to our main activity that jobs aren't here.
I specified that be in line number 28.
I am setting the layout manager.
So this is very important recycled view that sets layout manager.
And here I am actually creating a new instance of linear layout manager.
Why.
Because inside this activity underlaid minute example here we have this recycle view Enceladus linearly
out.
So in order to specify a layout manager of this recycle view you need to say that we have a linear layout
manager and we pass this context to mean activity that this here to this instance here in line number
15.
As you can see in line number Fritzy if you have this line of code firebase database that get instance
that said persistence enable true.
So here I am enabling the offline capability of firebase.
And here I am initializing this database reference database reference assignment operator firebase that
objects that get instance that get reference in this way we can actually access to a reference the the
firebase database instance and we can have a reference to that instance.
So now let me show you the web browser.
And as you can see here this is our firebase database instance and then we want to initialize our database
reference we need to have a reference to this instance.
So that's why I am saying get reference at a lower number first to 42 as you can see here we are.
We want to actually again enable the offline capability of firebase So again we must put this line of
code here database friends that keeps seemed true.
So now here in as you can see we need to actually to initialize these valuable firebase the cycler adapter.
But first Vinit to have a view there.
So let's actually create and hold the class.
Actually this is going to be an inner class.
Right.
So inside of the class and after the end in calibrates of this uncreate effort and before the end in
calibrates of this class mean activity inside this class.
I want to actually create our view that a class act is going to be an inner class.
Right.
So here I can say public static class public static class and the name of our class is view.
All right.
So if you hold there and this class is going to actually extend recycle or view that view they're right
and that I need to open and close this class by using these curly braces and opening curly brace followed
by closing curly brace and now of any to actually pro-white a constructor for this whole.
So here I can't say public and the name of the constructor must be the same as the name of the class.
So public view hall there and here as you can see I need to actually put a pair of Prentice's here and
then I need to open and close this constructed by using these curly braces and the inside Apprentice's
of this constructor because I want to initialize the constructor of the superclass when to actually
put on an argument of type view and the name of this argument is item view.
Right.
So this is the view is actually the type of the argument and the item view is actually the name of this
argument.
And now let's go inside the constructor.
First we need to initialize the constructor of the superclass.
So super item view.
So now we have no errors.
And as I told you earlier in this teacherly or in this application we want to use our only out our only
out for item view.
Right.
We created this custom row.
And as you can see here we want to use this row inside our recycler view.
So inside is a main activity class here first insight is in a class view holder.
I'm going to actually declare some variables.
So takes few takes the Buxar name takes the boxer name semicolon takes the view takes the box there
takes the punch power takes the punch power semicolon takes view takes the punch spit takes the punch
speed write semi-colon.
So we have these valuables.
So now let's actually initialize our valuable insight are constructed of this whole class.
This is actually an inner class and I told you that for inner classes we use static keyword.
Right.
So now up here inside this custom row you can see that we have these tapes view here which is actually
actually box or name.
And the second one it's ID ECAC punch power.
And the first part is actually the point speed.
So this is going to be our Actually our all right our only out for the item view and inside an activity
class and Enceladus are in a class of your Holder as you can see we actually declare these variables
to the boxer or to the punch power and the expanse speed.
So now let's go inside this constructor and initialize these variables.
So the box or an assignment operator.
And then I need to cast this object around to take the view object and here because these text views
are going to be inside an item view.
Right.
We have this item in view from the constructor right here we just need to say item view dot find view
by ID or thought Id dot takes the bulk surname semicolon and then here takes the punch power assignment
operator and that I need to cestus object to a text object item view that find view by ID are but Id
that takes the punch power semicolon and takes the punch speed assignment operator.
And then I need to cast this object to a text view object item view that find view by ID are that Id
dot takes the punch speed semicolon.
So we declare and initialized these objects these valuables which are of type text view.
And here let's actually pro-white another view.
Another variable here.
This actually the insight is in a class A holder and can actually create another invaluable so view
and the name of this variable is you write semicolon.
And now I want you to get the item view so that whenever we actually have access to an object of view
holder we can actually access that item view so that we can actually make that if you are an unclick
listener we can make that view a listener through the clicks of the user.
So here I have a view assignment operator item view.
So this item view is actually is actually the view of each cell.
Right.
So in this way we can have access.
We can have access to the item view.
So now let's actually go inside our uncreate Smurfette.
And here we need to actually initialize our firebase recycle the data.
Right.
So here I can say firebase recycle adapter assignment operator new.
We need to create a new instance of type firebase recycler adapter.
So I just need to hold the shift key on my keyboard and then press until that key on my keyboard.
And now the autocomplete feature of Android studio is going to help me to choose this option.
Firebase recycle adapter.
So the first option here and the person interviewing on your keyboard.
And now the autocomplete feature actually helped us to automatically put these lines of code here.
Right.
So after the end in curly brace put a semicolon here and it was to provide some arguments for this construction
of this firebase recycle adapter.
So the first argument is actually the model class.
So the model class you know is the Boxer class.
Right.
And there's such an argument as I can see is the model lay out.
So we need to provide the lay out.
So I told you that we have our own lay out in this application which is this one custom underlined row.
So in this time I want to use this custom underline row.
Right.
And the first argument is going to be the view the class that we have here which is actually an inner
class view holder and a fourth argument as you can see here is actually that database reference.
So model class model lay out the whole class and reference.
So the model class is actually the boxer class self self-taught class.
So it may actually create a new life here comma.
And the second argument is actually the model lay out.
So here I told you that we have or only out custom on the underlying rules so here I can say our thoughts
ID dot our DOT lay out dot custom arrow right.
And then he had this is actually our only out right for each row.
And for the first argument we need to pro-white the view hole there as you can see here we have this
view holder class.
Right this is actually an inner class.
So here I can say a V hole there.
But class comma.
And for the final argument we need to actually refer to our database reference and now as you can see
here we have no errors.
We actually put all these arguments here.
Right and now we can actually work on this populate view whole method.
So let's actually go inside the curly braces of the Smurfette populated you Hodell.
And now I want to actually get the boxer name punch power and punch speed right.
So here I can see a real hole there.
So as you can see we actually get this hole there from this.
MF It is actually an argument of this if it is an object of this view holder.
So when we actually refer to this object the constructed here is going to be called automatically.
Right.
And these variables are going to be initialized.
So here we have you hold the dot and now we can access this very well so I can say if you hold that
that takes the Buxar name dot set text right.
And here we have this model which is a boxer.
And here I can see a model that gets Buxar name right.
And in this way we can actually to get a box of name and put it inside our recycle over you and each
row has free text views right.
For example the first one is that takes the box only.
So in this way we can actually get the boxes going from the server and put it here.
So let's go back to our main activity class and here view holder that takes the punch power that said
text model that gets box set get punch power if you Holar that DXi punch speed that said text model
that gets punched speed and now we can see that you have actually used these text reviews and we get
these data from the server.
So now up after the end in curly brace of this adapter we need to say that recycle view you right dot
set it after we need to set the adapter for this recycler view and the adapter is firebase recycler
adapter.
So firebase the cycler adapter.
This is very important.
If you don't put this line of code here your application is not going to work.
So let's actually run our application now.
And here too is one of these virtual devices.
And then click on OK.
So as you can see here our application crashed.
Right.
So I told you in order to find out why your application crashed UNITA code translates to you and at
about then click on Android monitor.
Right.
And then here we can actually find the error.
So here let's actually scroll to the top and it says I told you to find the fatal exception here and
it says Main.
So this means that the error has occurred in say the main threat.
And now here let's actually see the error and it says that on Android that content that the arrest that
resource is not found exception stream resource ID right.
And here we have these links so we can actually click on this link here.
For example this one.
And now it's actually called Android studio.
And it says that the error occurred in this line.
So we have another link.
So we have this link here and it says that the error occurred in this line of code.
So the first line which is actually a little bit more helpful right here it says that the error Error
Occurred in this line of code and when the flow of our program breached to this line of code our program
crashed.
So why this happened.
Can you figure out why this happened this happened because the punch power is actually an integer value.
And this set takes Smurfit needs a strange value right.
I told you in the adult section of the course that this text Nefert needs a string value.
So here we I truly didn't convert this integer value to a string value.
So in order to convert this value this integer value to a string value I just need to put a plus operator
here and then I put two double quotes.
So in this way we can actually convert this integer value to and twice think value.
And here again we are getting this punch speed which is actually an integer value.
And this text if it needs a single value so we need to change this value we need to convert this integer
value to osting value by putting a plus operator and two that Alcott's.
So let's look at our application again.
So as you can see here our application is running on the simulator.
And here we can see the data that we get from the server.
So a 100 or 200.
Now let me show you the web browser here.
So let me show you the emulator.
Now we can see that we have these objects right.
And the name of the boxes is a the punch power is one handed.
And the punch speed is 200.
And we have another boxer right.
And its name is be the punch power is 10 and the punch speed is 20.
And it goes to the to that down as you can see here we can see all these other pucks that optics right
now.
I want to show you the unclick listener right how we can actually make these views for example that
the user clicks on this item and we need to be.
I want to be notified whenever the user clicks on the spot.
This is me on this item view right on the set.
So in order to do that let's go inside this populate view Holder's method.
And here I can say as you can see if you get this view hold that right this view holder holds the value
of this item.
So now we have access to this view.
So here I can easily say View hole there right.
That view.
So now we have access to that item view.
Right.
Let's scroll down here.
As you can see I created this valuable view inside this Nicholasville holder and inside this constructor
I am assigning this item view to this view.
Right.
And in this way we have access to this item view.
So if I show you the emulator as you can see we have this item view right and we can make this item
view a listener to the clicks of the user.
So let's go back to our uncreate Meffert and insiders populate a view holder method.
So you hold that view that set unclick listener right.
And in this way we can actually make that view and unclick listener.
And here I need to create an instance of type uncle in a Suneel view that unclick listener.
Right.
And now you can see that again we have actually an anonymous inner class and not anonymous in a class
is actually conforming or implementing this unclick within an interface and that because that anonymous
initialises is actually implementing this unclick is an interface that Cholas must provide an implementation
for this method.
So let's go inside this uncle my friend and here I can say for example TOSed that make text and for
the first argument we need to provide the the context I mean activity that this comma.
And for the second argument I can say that this item is clicked comma.
And for the first argument we need to specify actually the length the duration that this host is going
to be shown to the user.
So you want to choose Shortland that's short.
So host that line that short.
And finally we need to call that show an effect on this object on this toast object.
So now let me create a new line here so that you can see this toast object here better.
So let's run our project now.
Let me show you the emulator.
And now as you can see we have these items.
And let's actually click on this item here and it says this item is clicked or I can I can also get
the position of this item as fast as you can see here.
This populate the holder actually has an argument of type integer and its name is position.
So here I can say this item is clicked right colon plus position.
Let's run our project now.
Let me show you the emulator.
Let's click on one of these items and it says this item is CLEET zero.
So the position of this item is zero.
Right.
And it says this this item booklet is free.
And all these other budget optics right.
So hopefully that makes sense and I think that's enough for this theater.
Also if you have any questions about these concepts that I hurt you in this lesson please.
What's the discussion in the course.
I do my best to answer all of your questions.
Thank you very much for watching and I'll see you in the next year Toria.