So before the add some lines of code here inside this on share through friends change.
Smurfette First of all let's actually create a reference to our main activity for argument.
So now let's actually scroll top and actually go inside this class as you can see I am actually inside
this main activity class and now I want to actually create a reference to our main activity for humans.
So he has just type in his main activity fragment and just name it my animal quis fragment and then
put a semi-colon at the end.
As you can see here I am actually declaring or reference an instance actually of type man activity affreightment.
And now let's actually go inside this main activity fragment the java file.
As you can see here inside this class we have we have actually some effects OK.
So in order to use these methods of inside are actually an activity class we need to create a reference
to our main activity fragment inside our main activity class.
Right.
So in order to use the methods that we created inside Isman activity for argument we need to actually
create an instance of type an activity fragment inside this main activity class and then we can actually
use those methods.
So now as you can see here in line number 30 I actually declared an instance of pikemen activity regiment.
And now let's actually go inside this uncreate Smurfette and he has just referred to the name of this
instance my animal quiz regiment assignment assignment operator.
And then I actually cast this object to a main activity fragment object and here just type in here get
support of manager thought find fragments by ID and he has just opened here.
Odd thought id that animal cuius fragments.
So now just put a semicolon at the end of your statement.
And now let me show you this structure of the project view tool windows and then project and now as
you can see here it's actually going so these are.
And then go inside this rest folder and go inside this layer folder.
And now as you can see here.
Just double click on this content underline Minutemen minute example as you can see here we actually
put this fragment here right.
So if you look at the Aldie of this fragment here as you can see the OT is animalcules fragment right.
So inside this main activity class I am actually creating a reference to this.
The fragment that we put here inside its contents.
Underline minute minute example as you can see here.
So the idea is animalcules placement as you can see here right.
So now let's actually go inside this main activity class and now let me actually double tap here in
order to make this area Vider.
So I actually created a reference to this man this animal fragment.
And then I assigned that reference to this my only increased alignment.
So every time that I referred to this my sprite meant I can actually access this fragment here right.
So now you can see that main activity AFFREIGHTMENT or java file actually is loading this animal cuius
fragment.
Right so now let's actually go inside these and share the preference change method here as you can see.
And now I'm going to pasting some lines of code and then I'm going to explain to you what's going on
here.
So now as you can see here these are the lines of code that I pasted here.
So now let me actually highlight the lines of code that I actually pasted here.
Now let me try to explain to you what's going on here.
Step by is there so now as you can see in line number 87 I actually just referred to the name of our
valuable IIS settings change.
Right.
So I actually assigned the value truth to this value but sooner if I actually scroll to the top here.
As you can see in line number 25 we actually created this variable which is a boolean and the name is
setting's changed.
And initially I assigned to devalue Follett's to this variable.
So let me show you the emulator.
So whenever you use it actually changes the settings of the application.
The settings of the keys.
Then we're going to assign the value true to this is settings change the value.
But initially we assign the value of force.
So let's actually go inside the Smurfette and Shirly friends change the method.
So this effort here is going to be called every time they use it changes the settings of the application.
Every time you use it interacts with the settings of the application then this will get that this is
going to be executed.
So in that case we are going to actually be assigned about you true to this valuable is that exchange
is true.
Right.
And now we have actually an if statement.
So if so as you can see here we actually received this key as an argument from the Smurfette right.
So on shirt preference changed actually it gives us two arguments the first argument is of type shirt
preferences and the name is shared offenses.
So we're going to get the shared preferences of the application so that we can actually get the settings
of the application get the actual values of the settings right.
So share preferences shirt preferences and then we actually also get the key right.
So the key of all these items for example the number of guests is key.
The animals type key by uncolored key or the front for keys key right.
So we also get the key from the Smurfette.
So in that case we are actually saying that if the key is equal to guesses.
So let me actually scroll to the top here.
As you can see we actually created this key here in number 19 settings underline number of guesses right.
So every time they use that is actually every time to use that changes the number of guesses here.
As you can see two four or six then we can actually get the key here as you can see every time these
changes the number of guesses.
Then you are sure that the key is guesses right.
Now this means that the user has actually interacted with the actually settings with the number of guesses
item.
So now we are going to execute this if statement right.
So if cheap that equals guesses then it's going to execute.
First of all this line I've got here my animalcules fragment.
So here I am referring to this my Ahlquist Frank fragment.
So I actually created a reference to this main activity for argument and the name is and the name of
my reference is my name on cuius fragment that modified animal grassroots.
So as you can see here with this class main activity does not recognize this method.
So now let's actually go inside the main activity fragments class and now as you can see here inside
this class I actually made a mistake and I actually did put the first letter of the name of my Millford
capitalized as you can see here the first letter of the name of my method modified is actually chappal
capitalized.
So this is Ron.
This should be the actually lowercase M.
And now it is right.
Modify animal guestrooms right.
And now let's actually go inside this main activity that are right here and now as you can see here
the error is gone.
My animal is argument that modify animal just throws.
And we actually passed this shirt preferences here as an argument from this Ancilla preference change
center.
So we get to show preferences of the application from the Smurfette.
So when they use that actually changes the guesses as you can see here for example two four or six.
Then this effect here is going to be executed.
And and here we are actually checking that whether the key is guess's or not.
So if the key is guesses and this means that if they use that actually interacted with the number of
guesses option then as you can see it's going to actually modify animal throws then it's going to go
in.
So the main activity fragment class as you can see here and it's going to execute the Smurfit modified
animal just throws.
So let me actually go back to our main activity class and then here we're going to reset the animal
quiz.
So now if I actually change for example the number of guess is to not to two as you can see here it
says new changes are applied.
And if I click on this right in here as you can see our queen is now reset.
Right.
And we have to guess options.
So as you can see here we have another else if statement so else if the key is equal to animal type
and this means that if the user actually interacted with the animals type.
So for example if the user wants to only have wild animals or the animate might want to have only tame
animals all that maybe the user wants to have both of these types of animals wild animals and tame animals
inside quiz.
So for example in this case I want to have only wild animals in my case and I just checked the sequence
here and I and I uncheck the safe box and then I click on this.
OK.
Here as you can see it's as new changes are applied.
So first as you can see LCF cheap that equals animal type animals type.
So this is the key right.
So this means that if the user has interacted with the animals type then first that will be create a
set of streambed values.
So a set of sync values and the name is animal types.
Assignment operator so shares preferences.
So really first this shows the difference is that we get from the Smurfette.
Does it get strange.
So if we get we call this it gets thing set as you can see he has shared preferences that gets things
set.
And in this way we can actually get a set of values right.
And we actually passed the key as you can see here.
So by passing the key to the Smurfette get string set we can actually get those values as you can see
here.
And for the default value we passed that value null and now these animal types set now actually contain
the animal types and then actually we have another if statement inside this.
Else if statement as you can see here.
So here we are taking that if animal types is not equal to not if this animal types said as you can
see here is not equal to Kunaal And if these animal types that size is actually greater than zero.
And this means that if these animal types here as you can see here is not equal to not and this means
for example the user might actually uncheck.
Actually my Antek both of these checkboxes as you can see here and in that case we are taking that if
at least one of these checkboxes is checked.
So if the animal types is not equal to an owl and if animal types this size and this means if the values
if the size of the values that are inside of these animal types is actually greater than zero.
So this means if the number of values actually that are inside of these animal types is actually greater
than zero then it's going to execute this statement and it's going actually call.
Going to first of all are the first to the name of this fragment.
My animal is fragments that modify the type of animals in Queens.
So if we are here we are calling the Smurfette and we passed this shared preferences to the Smurfette
And we also want to reset the animal cuius.
So now for example let's check the sequence here.
Wild animals and then click on OK.
And now let's actually come back to put in here.
As you can see here now we have only this actually the wild animals.
So for example let's actually click on shark.
Now as you can see here the next animal is going to be also an animal a wild animal elephant.
And now it's actually the church.
And then as you can see here lion.
Let's actually check out other animal dog.
Right.
So as you can see here we have only wild animals inside the quiz.
So now we have an else statement and this statement here says that if the actually the value of these
animal types is actually equal to nine all or if the animal types that size is not greater than zero.
So this means that if they use it for example do not actually take both of these checkboxes as you can
see here that in that case if they use that click on OK here then it says one type of animals must be
selected.
Right.
So here as you can see if we create a shared preference says that editor to show references that editor
and that name is editor assignment operator Scheft references that get it right.
So in that case when the user do not want to have any types of animals in say the quiz then in that
case we are going to actually provide a default type for the quiz because if you if we don't actually
provide a default part of the file type for our quiz then we cannot actually starts the quiz.
So we should have at least one type of animals of wild animal or tame animals inside the quiz.
So as you can see here first of all we actually create an edited object so sharply Frances that editor
and the name editor write assignment operator shows preferences that edits and then actually the first
to the name of the set and command types start at.
So here I want to actually add value to the animal types set as you can see here.
I actually created this set inline number 96.
So animal types that at and then I call this if it gets strange in order to get a string value and then
I pass this value here are that strange dots defaults animal type.
So now as you can see here we haven't still provided this different animal type String resource here.
So let's actually just select disvalue default underline animal underline type and just hold the comment
on your keyboard and then personally the key on your keyboard and then let's actually go inside the
settings.
Let's go in.
So this is 3x that exemplified.
And now let's actually create a single source.
And the name just for the name just paste that's value here.
Default on the line animal underline type and then disclose this value here.
So for the default value I want to have wild animals inside my house.
So just typing here while with capital W anemones.
So now as you can see here we have this value void on the line.
Animals.
And now let me show you the structure of the project.
So just click on View tool windows and then project as you can see here.
Inside is Apfel there you have these assets what they're right.
So the name of the default value that you provide here must be then the name of Deb of one of these
values take underline animals or wild animals.
And this name must be the same as these names team on the line animals or wild underline animals so
I chose the wild Underland animals as the default value.
So let me go back into our main activity of a fight as you can see here.
So as you can see here the arrow is gone.
Get string on that string that default underline animal.
So we actually added this type to these animal types and now again we actually fed to the editor here.
So editor that puts things set.
So if you want to actually put us string set to this editor so editor that would string said animal
type as you can see here animals type.
So if we passed the key and then we need to for the second argument we need to pass the set as you can
see here.
So editor that puts string said for these key animals type animal types as you can see here and then
we call Ed. that apply.
And now we actually created a toast message here tossed in message.
So TOSed that make takes I mean activity that this and here are three in the first animal type underline
message.
So here we can actually just change this value to for example a toast message toast message.
And now let's actually copy disvalue because we haven't still provided a value for this.
We haven't stood still provided a single source inside our strings that examen file.
And he has can see Towcester then short.
Here we are specifying the duration of this message and we need to actually call this to show him if
at this object.
So that's show.
So now let's just copy this value here TOSed underlying message here.
And let's actually go inside these strings that they say modified and here let's actually create a stunning
resource and for that name just place that value here.
Underlying message and then close this tag here and just type in here.
And when a person of value here.
And then I'm going explain to you what's going on here.
So as you can see here I pasted this about you here.
One type of animals must be selected.
The default value is wild animals.
As you can see here.
Right.
So we're going to show this message to the user if they use it actually doesn't change.
Neither of these options neither of these checkboxes right.
Avoid animals or tame animals.
If they use it it doesn't check.
Neither of these checkboxes.
And then click on OK here.
As you can see we don't actually provide this message in order to show to use it but here because we
already didn't provide a value for these checkboxes.
It didn't actually show us that message.
So let me ask you to choose animals and then click on OK.
And now let's actually click on these animals here again and this time this actually on take the box
and then click on OK as you can see it one one type of animals must be selected and the default value
is white animals right.
So now let's actually go back into our main activity class and here we are going to show this message
to the user if the user doesn't provide a type for our quiz.
OK.
So let me actually I need to explain here this LCF statement because this is very important so that
it would make sense.