Hello everyone.
So now here in this tutorial we're going to go ahead and we're going to provide an implementation for
this method.
Modify user interface.
He had inside this main activity class.
OK.
So let's go inside the curly braces of this method.
First are going to actually create an add a list of all martial art objects that we have insight or
a skill like database so I can say aerialist and inside the angle brackets we need to specify the data
type of the updates that we have inside these ideas which is going to be martial art the name of this
artist is going to be all martial art objects assignment operator and in here I just need to refer to
this database handler reference that return all objects semicolon.
So let me create a new line here so that you can see what's going on here.
Now I can create an if statement here.
So if all Monserrat objects that size is actually greater than zero so this means that if there is actually
a marshal object inside these Wrigley's here then you can go inside the curly braces of this if statement.
So here first of all you want to refer to this scroll view that you have inside is content on.
In that example scroll view that remove all views in layout.
So why do I call this method here because I want it this actually.
Every time they modify user interface it's called I want the views that are actually inside the scroll
view to be removed first.
OK.
And then I want to add them at the newly actually updated marshal hot buttons to the scroll view.
So after this line of code I can't say here let's create a greedily out secretely out and here the name
is clearly an assignment operator new grittily out Kate.
And here we just need to pass the context which is going to be main activity that this semicolon.
So let's refer to this great layout that sits row count.
Let's specify the number of rows that we're going to have in say discretely out said throw count.
And here you can see that we need to pass a value of type integer as the number of rows of our great
layout.
Right.
But here let me tell you that each row is going to have two columns.
Right.
So this means that many to have actually an even number we don't know how many martial arts actually
emotional buttons we're going to have inside our layout inside our scroll here because we're getting
these modular objects from the database from the SGI like.
We don't know how many monster objects are there.
So in that case this means that in order to specify the number of rows of our greatly out first we need
to access the size of this Aurelia's.
So let's put another pair of practices here and refer to these all martial art objects are a list here
and just type in here that size and just put plus one.
And then here the result of this operation here is going to be divided by two.
That's why I said we need to have an even number for that for the columns of each row.
Right.
So for example assume that the size of this all Monserrat all Monserrat objects actually are a here.
This radius is going to be for example nine.
We have nine Montral objects inside this radius.
Right.
So according to this operation here nine plus one is going to be 10 right.
So 10 divided by two is going to give us the value number five.
So in this in this case we're going to have five rows that can have two columns each.
So now imagine that we have 10 modular objects which is an even number right.
Imagine that we have 10 martial artists inside this radius so 10 plus one is 11 right.
So 11 divided by two is going to be a 10.
What fight is going to give us 5 rows.
Why.
Because these sets count method needs a value of type integer.
This means that we can only pass on value of that integer to this method.
We cannot pass a value of type float to this method.
And in other words if we pass a value that is actually the decimal decimal value to the Smurfit that
this symbol value after the decimal point is going to be eliminated.
This method needs only a value of type integer.
So 11 divided by two is going to be again 5 and it's going to give us five rows.
Right so that we can actually assign we can actually put our Monserrat buttons in each row.
So for now if this doesn't make sense don't worry I'm going to explain it again later.
For now I just write this formula here and now after this line of code let's specify the number of counts
that actually the number of columns of each row so greatly that sets column count which is going to
be number 2.
And here let's create an array of marshal or partons.
So I can say martial art but in and pulled up out of practice here and here's a snippet here that Button's
assignment operator new martial art foughten and inside the brackets meaning to specify the size of
this at eight.
So according to the martial art objects that we have inside this Aurelia's we are going to specify the
number of elements that we're going to have inside this at 8.
So it is going to be all modular objects that size right semicolon that may create a new line here so
that you can see what's going on here after this line of what I can't say because I want to be notified
because this class main activity class is going to be notified when to use it interacts with the emotional
buttons of this class marshal of this class.
And if the class is good must actually implement the view and click the center interface.
So let's scroll to the top here and here it says main activity extends up compact activity implements
view that Uncle listener on click listener right.
So because this class now is implementing this interface view that Dunkley class and Elvie must provide
an implementation for the move here inside this class.
So let's scroll down here.
And before the end in curly brace of this class here main activity I can't just step in and click.
So now you can see that we actually override this method here on Cleage So let's scroll through it up
here and let's go to this actually to this method for user interface Meffert after distrain of code.
Now feel are actually are greatly out with martial art.
Partons So first let's create a variable of type integer and it is going to be the index assignment
operator zero semicolon.
And now let's create a for loop here so for and here I can say martial arts and the name of this valley
of it is martial art object call an and let's actually iterate over the objects that we have inside
this Aurelia's all objects.
So let's open and closed this for loop by using these curly braces.
So first of all let's create a martial art object for the index here that we created here of this idea
of this martial art.
So I can refer to this monster that buttons at a.
And I put a pair of brackets here and inside the brackets I can refer to this index.
Right.
All you want to create are martial arts a button for the index of this array.
So I can put an assignment operator here.
Space assignment operator new martial art.
But in this instance of type of button needs first we need to pass the context we are calling the constructor
of this class right.
First we need to pass the context which is going to be an activity that does come on.
And then we need to pass the martial art here.
Are specific martial art object which is going to be this one object.
We have this variable here.
So martial object cynical.
Let me create a new line here.
So that's it.
And here let's specify the text of each martial arts button so I can say marshal hot buttons index dots
sit Tick's.
So first we're going to get the text of the martial art object and then we want to output the price
of that martial art.
So first I can say martial object that gets martial art name plus two coats Bideford slash n and then
here I can say plus again Marshall object that get Marshall Price.
And here you can see that if we get the Marshall name and the Marshall Price we also can output the
ID of each module object so I can say a martial art object that gets that ID plus two quotes two quotes
and then put a back for Slash in here and again put another concatenation operator.
Let me create a new line here so that you can see what's going on here exactly.
So you can see that for the text of each Marshlack button with first the output the ID of that martial
art.
And then we put our passports and hid in order to create a new line here.
And then we say we want to output them.
Marshall name Michael net.
And then finally if you want to put there Marshall Price.
So now after this line of code here I want to specify the color of each martial arts Potin.
So I want to change the background color of each Marshall button according to the color that the user
has specified.
For example in say the update activity or inside the for example at marshal or activity class.
So let's see how we can do that.
Let's create an if statement here and I can refer to this modular object that gets martial arts color.
If martial arts that get martial of color is for example equal to and I put on here I want to hard code
this value I can see red I can do something about this one.
Are you open and close this may for this statement.
I use it by using the curly braces but instead of creating an if statement here it's better to create
a switch statement let's delete this statement here.
Now let's create a switch statement switch.
And now I can refer to this monster object that gets martial arts color get rid of color.
So I want to switch between the values of the color of each module object.
Let's create and chase a case statement and here I can see a case and I can put two two quotes here
because the return type of this method get Marshall that color is actually the string.
Right.
So I can't say that if the value the return type of this and that colored my head is actually red which
is the return value actually if the returned value which is of type string is actually red.
I can put a colon here.
And now I can say that the marshal or buttons.
And then I put a pair of brackets index doth sit baculum color set back in the color color.
Dots red right.
That's it.
And that I can for example say bridge break means I actually break out of these suits.
So it's going to go after the ending curly brace of these three separate statements and it's going to
execute the other quotes here.
So now after this case I can create another case.
Case two coats for example blue co-lead.
Here I can see Marshall hot buttons.
And then I put in x year in the brackets that said background color that's a given color for example
colored that's blue color that's blue right and then break.
Let's create another case of statement so case two coats black.
And I put a call in here and I can say martial art patents index that said background color color that's
black.
Break again.
Chase two coats for example.
The color yellow yellow color and Marshall buttons index that sets by color color dots yellow and then
break.
And here I can create another case.
So case two coats.
And for example the color of gray or the color purple I think purple colon.
And here I can see Marshall patent's index that said color color.
That's purple.
So as you can see if you don't have the color purple here.
So let's instead choose these colors you see on break.
And in order to see what colors do we have here.
So I just to refer to this color class that we have the blue green red and Ulfar you can see all these
colors here.
So we can actually create another Chase's segment for that green color so I can say chase two coats
green color.
I can't say Marsha that buttons index that sets the color color that green color.
That's.
And then here I just need to put a break statement here semicolon.
And finally let's create a default case here.
So default and if none of the cases above is actually true here I'm going to specify that the color
of the pattern is going to be gray.
So I can't say much about Patten's index that sits by Guaran color and here I can say color.
That's great.
That's it break.
So now we can also create another case statement so before this default statement here I can see a case
for example color two coats and the color is going to be for example white light white color Marshall
pitance index that sits on color colored that flight.
That's it.
And then fraiche so I specify these colors here for each martial art pattern.
So after the ending curly brace of these suits me here I can actually create some logic here.
So here I specify the colors of each monster that pattern that I am still inside these for in loop here.
OK.
This is the ending curly brace of this for in loop here right.
So before the ending calibers of this for in do you want to actually create a listener for each Marshall
button.
So I can see Marshlack buttons index that sits sits unclick listener and when it was past the context
which is going to be main activity that this because this main activity class is implementing the view
that unclick listener interface so we can pass this context here.
And finally we need to add these Marshlack buttons to our great view.
So I can say great view and truly great play out that view.
So first we need to pass the child is going to be Monserrat buttons index.
Right.
And then we need to specify.
So just put a comma here.
Here we need to specify the width of each Marshlack button.
So I already created a variable that actually holds the veto of the button so I can refer to that Monserrat
button with Marshman or button with comma.
And here I just need to specify the height of the martial art button so I change.
I can see View group thoughts lay out perhaps thoughts wrapped content.
So let me create a new line here so that you can see what's going on here exactly.
First we specified that if are going to have a listener for each marginal object he had the button actually
and that if we added these martial artists these martial patents to are greatly out here and we specify
the beat and the height and here after the end and curly brace of this for in loop here I'm going to
add this great play out this great you to our scroll view.
So I can say scroll view that I view greed left.
So before the end in curly brace of this if statement here the at this line of code here.
Right.
So this is RMF it modify user interface Smurfette.
So let me tell you that we call this method inside the uncreate Smurfette modify user interface and
we also want to call this method inside the resume method.
So why do you want to call this method inside the presumed effect because when we actually for example
transition to a delete activity there we can delete for example some of the objects some of the objects
that we have inside our database.
So in that case if the user goes back to the main activity there the uncreate method is not going to
be called the did they all resume if it is going to be called.
So you are already familiar with the app and realize lifecycle methods the uncreate and if it is going
to be called for the first time for all or for example when the user actually runs the application.
There are uncreate if it is going to be caught.
But when the user transitions to other activities and goes back to their main activity the uncreate
of it is not going to be caught.
So the old resume if it is going to be called so we want to actually at the Create want to modify the
user interface inside the resume effort when the user actually transitions to for example other activities
and then goes back to the main activity.
So it's better it's better to actually call this method inside our own resume if it too.
So here let's scroll down here.
And before the end in curly brace of this main activity class I can just step in here and resume.
And here we can see that I override it this method on resume if this is a lifecycle method of Android.
And here I can say modify user interface.
Right.
So if you don't understand why I actually called this misfitting So it is a resume if it don't already.
Let me run the application and then I'm going to explain it again.
So let's run the app now and here let's select one of these devices and then click on OK.
So here you can see that our application is running on the simulator.
I can actually scroll between these buttons here as you can see we have Marshall buttons and we can
actually click on them here.
Right.
So you can see that the back end uncolored of all these modular buttons actually blue.
Let's go to the update at demodulate activities here.
So let's change for example the color of this one to.
Right.
And let's see we can modify and let's actually go back to our main activity here you can see that now
the background color of this Marshlack pattern is red.
Why.
Because we call it.
This may fit inside this honorees method.
Right.
So when we for example go to the update marshal activity class here if I click back here now and resume
if it is called not the uncreate method but the resume if it is called.
So that's why it is actually necessary to call this method modify user interface inside this on resume
effort.
So for example here as you can see when we actually click on these modular buttons here nothing happens
right.
So let's go back to android studio and let's pro-white and implementation some implementations here
for this Anklage method.
So let's go inside the Smurfit here.