So now I'm going to pasting some lines of code here inside this class and then I'm going to explain
to you what's going on here.
So before the end in curly brace of this class here as you can see this is the end in equilibrate of
this class.
So before the end in curly braces this class I'm going to paste in these lines of code here.
So as you can see here these are the lines of code that I pasted here and now I'm going to explain to
you what's going on here.
Exactly.
So now let's actually look at this method.
Here we have our method right.
And now as you can see here the axis of this method is public.
The return type of the Smurfette is void.
The name of the Smurfit is modify animals guess Rose as you can see here.
And this method actually accepts one argument of type shared preferences and the name of this argument
is shared preferences.
Right.
So now as you can see here let's go inside the curly braces of the Smurfette And let's see what's going
on here in line number three hundred and eighty nine as you can see.
We have actually a constant and the name as he has here that data type of this constant is string.
And the name of our constant is actually number of guest options.
So here as you can see we have a constant that can hold of idea of type string.
Right.
So final strange number of options.
Assignment operator and that I referred to the name of this actually to the name of this argument shared
preferences that get strange.
And now as you can see here I am actually referring to this guess as to this case is here.
So this case is here.
Actually first to this guess Chih that we have inside this main activity class.
Right.
So analysis I should go inside this main activity fragment that of a fight here.
So now let's just type in main activity that classes are now in this.
You can understand that we are referring to this this is key that we have inside this main activity
that double wide.
So this here this constant actually holds this key settings underline number of guesses.
So now if we actually go inside.
Actually let me show you the structure of the project.
So just click on View and then tool windows and then click on Project.
And now it's actually double click on this red folder and then let's go inside this values folder and
here as you can see we have these XML files and now let's actually double click on this XML file here
as you can see the DoubleClick and the xml folder and then double click and the squeeze underline preferences
that exemplified.
And now it's actually double click on this a tab here quis underlying preferences that exemplified in
order to act in order to actually make it make this area Vider.
So as you can see here inside this file we have actually a list preference right.
And this is preferencial actually holds the number of guest list as you can see here.
And the key is settings underline number of guesses and the title is as I see it as you can see here
number of cases total.
And if I actually hold up the comment the comment on my keyboard as you can see here and then click
on the title here as you can see it's a number of guesses right inside strings that exemplified.
And let's go back into our Q Is Underland preference is that exemplified and here as you can see the
summary is this values Schu show two four or six gives options.
And now if I show you the emulator and if I actually go inside the settings but activity here as you
can see now if I actually click on this number of guesses here.
Now it says that we have actually two four or six options.
So here we have actually a typo number.
So now let's actually hold the comment here on the keyboard.
If you are using a Windows machine just hold the control on your keyboard and then click on this title
here.
As you can see we didn't actually put the are chelator here.
So a number of guesses right now is actually on our project again.
And now let's get you to go back into our quiz underlying preferences that examined by.
So now as you can see we have this preference yet and a persistent is true.
And this means that it can actually save our changes into their shared preferences file.
Inside our Android device and the default value is number four.
And this means that the default value of just options is four and we are going to have Fortius options
for our quiz if we don't specify our value for this.
Actually for this this preference.
So now let me show you the emulator here.
As you can see now it says number of guesses.
And if I click on it now for example if I want to actually for example if I select is 6 here I want
when I actually click on back button here I want to have for example says six gives options right.
Now let's actually click on this setting's activity and this number of guesses here and here.
If I actually click on this for example to here two number of cases and then click click on this patch
with and here.
Are you going to have two number of guesses.
Right.
Not six.
So we need to actually provide some logic for this.
So here we have this list preference.
And the key is settings underline number of guesses.
Inside is an activity of a fight as you can see here.
We created this color this constant here in say this main activity class and the key is guesses.
And then I put an assignment operator here and this this is actually the key settings on the number
of cases.
So we assigned this value to these constants so that we can actually refers to this constant in order
to access this value.
Inciters main activity affreightment our job here.
I want to actually provide this actually this logic here in order to allow the user to actually specify
the number of guest options that he or she wants to have inside the quiz.
So now as you can see this method actually accepts an argument of type shirt preferences right.
So has preferences that jet stream main activity so this if it gets through in here actually sits two
arguments right.
The first one is that actually the key.
So main activity that just that guess is as you can see here.
So in this way we can actually access this list preference that we have inside this quiz underlying
preferences that is similar in this way by actually reading what is key that you specified here.
We can actually access this this this list preference and then we can actually get the value that we
get from this actually from these radio buttons.
So as you can see here let me show you the emulator.
So for example if I go inside this setting's activity here and then click on the number of guesses here.
As you can see we have number two four or six.
So when I say let's actually go back into our main activity fragment of a fight here.
When I say share preferences that get strange.
So it can actually give us a string value right.
And now as you can see here in say this quiz underling preference is that exemplified the default value
is number four right inside the double quotes as you can see here.
Right.
So this is going to be osting value right because this value is inside double quotes.
So inside this way activity fragment that of a file when I say share preferences that gets three is
going to give us a string value.
First I need to specify the key.
So the key is main activity that guesses right main activity that guesses and now the second argument
is not.
So now let me ask you to call this method here again in order to show you the second argument.
So shares preferences that get strange
and now as you can see here that's the first argument is key.
And the second argument is the default value.
Right.
So here inside this quiz preference preferences that example I actually specified the default value
here.
So I don't need to provide a default value here again.
So I actually assign the value null for the second argument.
So let me read this line of code here.
So now let's look at this line of code here again.
So we have a constant the data type of this constant is strange the name of this constant is number
of options.
So this constant is going to hold the number of options that we use that actually specifies.
So assignment operator shares preferences.
So you can actually go inside the shared preferences that jet stream.
So it's going to actually get a string value and then it's going to actually pass the CI.
So because you want to actually get the number of just options as you can see here we need to pass the
key the key of this actually list this reference.
If I can say this squeeze Underland preferences that exemplified you can see that because I want to
get the value of this this preference right because these are actually radio buttons in say the radio
group we can only select one of them right.
So when I say get strange is going to actually only give us one of these values to four or six.
Right.
So now if I go back into our main activity fragment of a file you can see that I passed this key in
order to access that list preference and for the default value I passed the value null because inside
this quiz Underland preferences that exemplified for this this preference here as you can see here for
these key settings underline number of cases I specified a default value.
Number four.
So now let's actually go back into our main activity fragment out of a file.
So here now this string constant actually holds the number of options.
For example 2 4 or 6 because we are actually getting that value from these shared preferences.
So if you look at this quiz Underland preferences are exemplified here.
When we assign the value true to this persistent attribute of we actually said to the computer to our
Android device to actually save those changes to the shared preferences.
So when I actually referred to this shared preference I can't get that specific value right.
So Shetterly that gets trencherman activity that us and for the second argument null and then in line
number three hundred and ninety one as you can see here I actually referred to this valuable number
of animals guestrooms.
So now if I actually scroll to the top here inside this class as you can see we actually created this
variable here in line number 55 and disvalue is actually that integer and the name is number of animals
get throws.
So this value is supposed to hold the number of guests throws that we are going to have in say the quiz.
So now let's actually scroll down here and now as you can see here insight is actually inside the Smurfette
modify animals guess throws.
I am actually initialising despite the overall number of animals just throws assignment operator.
So now as you can see here we need to actually convert because as you can see here we're actually getting
this value as a string value right.
We need to convert that value to an integer value so that we can actually use it.
Inside our quiz so that we can actually tell the actual main activity here that we are going to have
for example six throws or four guess throws or for example two guesses.
That's bad.
You must be an integer value right.
So now as you can see because these values are actually string values when we want to get these values
here we are actually getting them as a string to.
For example two or four or six.
We need to convert them.
We need to convert those values actually to an integer value for example the value is too right.
We need to convert that number to an integer value.
So integer that parse.
Int.
And then we need to pass this thing value that you're going to convert it to actually to an integer
reduce the number of options as you can see here divided by two.
Why did I divide this value by two.
Why do they do that.
Just think about that.
And then we're going to talk about this line of thought here.