Hello this is Martez or karate.
And in this material we are going to completely implement our constructor here inside is my custom view
class.
First of all we need to create some instance valuables inside our class so let's do that now.
So remember what I told you about instance variables always declare your instance variables as private.
So let's do that private.
And now we need to specify the type the type is going to be of the integer The name is going to be View
color semicolon private in teacher.
And here we need to specify the text color which is a can of type Integer.
And finally private's 3 and it is green and its name is going to be view text semicolon.
So you can see that I declared this instance variables here right but let's switch to the my custom
view attributes that XML file here.
We created these attributes and according to these attributes I created instance variables inside my
custom view that Lafite.
So remember that whenever you create an attribute inside your XML file for your custom view make sure
to create an instance variable that is related to that attribute inside your class.
So here we created this instance variables.
Now we need to go inside our constructor.
So after calling the super constructor we are going to initialize this instance variables.
So how we are going to initialize these instance variables by accessing the attributes that we put inside
are my custom view attributes that identify by accessing these values.
We are going to initialize our instance variables.
So that's why I told you whenever you put an attribute inside your custom view that exemplified make
sure to create an instance variable inside your giallo fine for that specific attribute.
So we need to get inside my custom view that have a file inside the constructor.
After calling this Super constructor we're going to create something called typed Aure typed at 8 so
the name is going to be typed at 8.
Assignment operator.
Now we're going to say context that gets Feme that pain styled attributes.
So now first as you can see if you need to pass the attribute said call this function again you know
that just to show you these attributes these arguments that going to pass to this function.
First if you are going to pass the attributes set and then.
So let's actually pass the attributes here attribute set comma.
Now we need to pass the resource phi or the exemplify that we created for a custom view in order to
specify the attributes.
So we are going to say our DOT style of Eldard.
So here it is really important.
Let's go inside are my custom attributes that is in a file here as you can see we created attach called
declare style.
Its name is my custom view.
Right.
So now we're going to refer to this name.
Let's go inside are my custom be that have a file.
So it is our database that my custom view karma to specify a default value for this type attributes
the let's pass zero comma and again zero as the final argument.
So let me show you these arguments.
Here we have this default style attribute zero undefined style resource.
So let's put a semicolon at the end of our statement.
Let me create a new line so that you can see what's going on here.
So first we passed the attributes set that we get from this a constructor and then we are passing this.
Name the name of our custom view our style that my custom view and the value zero as the default style
attribute.
And about you again 0 4 the default style resource.
Now here after that you actually created this typed Arri we are going to create a try catch statement
here try and catch some exception.
So let's open and close this block by using these collaborations.
Let's go into these tribal.
So you are actually putting all coats here inside this right block.
Maybe actually something goes wrong so that we can actually catch the exception here because you're
dealing with a typed error.
Now we can initialize our instance variables.
So the first instance variable is view color.
So now we can say View color assignment operator.
Now we have this tied at a right.
So let's say types are a data type of our view color is integer.
So now we can see that gets in teacher.
Our dot Styler bill that.
So now we can access the color attributes the view color attributes that we created inside our my custom
view attributes that exemplify.
So we can say my custom view because the name of that style label attribute is my custom view and then
we have this text color.
We have this view color and this we have viewed text.
So we have this view color.
Let's use this one.
And we need to put a comma here and provide a default value for our attribute here semicolon.
Let me create a new line here.
Now the second instance variable that you want to initialize.
Is this a text color.
So let's say text color assignment operator again typed every that gets in teacher.
And here are dot style level dot my custom view and lets access this one text color comma and then this
has the value 0 as the default value semicolon.
Now let's initialize the view actually not the text.
So we have this mutex assignment operator times Ari that jet stream.
This time it is of type string.
So we get this strange.
And we see our That style liberal that my custom view view text semicolon.
Now inside this catch block we can say pipes aere that recycle.
So let me hold a comment on my keyboard.
You can actually do that and then click on is recycle here.
In order to see the documentation of this method if you are using a Windows machine you can hold down
the control key on your keyboard and then click on that second method.
Here take a look at this documentation.
Here take a look at this comment it says a recycles the typed Aure to be reused by a ladle color.
So if anything goes wrong in initialising odd instance variable this recycle is going to actually the
pipes are ready to be reused by a later color.
Let me close this file here.
Now that the initial eyes are instance variables.
Again I think that's enough for this tutorial in the next tutorial.
We're going to implement the underarm effect.
Inside are my custom view class.
Thank you very much for watching.
I'll see you in the next tutorial.