Hello this is Martez al-Qadi.
And in this story you are going to provide get Herods for our instance variables inside are my custom
view class.
So let's go inside the curly braces of our class here before getting curly brace of RMI like us of your
class let's create a comment getters for instance variables.
So now let's say let's actually take a look at our instance variables here.
The first one is the view color.
So let's say that we have public.
Remember I told you our Make sure to always declare your guitarist as Puplick because you may want to
use these get is inside another class so public and the return value of this method here is going to
be integer.
The name is going to be get View color.
Put a pair of perhaps this here and then open and close this Meffert by using these curly braces return
view color semicolon.
Now it's time to actually create another getter for our second instance variable.
So let's say you look at our instance variables here we have the text color and the view text.
So let's say we have Puplick
text Cotliar a pair of practices and here you going to return the color semicolon.
And finally we have the takes.
So again Puplick screen Get view text return view text.
So now that we have the getters for instance variables it's time to create the setters for instance
variables.
So we have Puplick voit set view color of her Apprentice's and let's create a primitive integer and
it is going to be color.
So if you are going to say that you have to view color assignment operator color semicolon.
And now we need to read there.
Our view is this is very important.
Now we are actually sitting and the view colored view or we are actually changing an attribute of our
custom view.
So we are going to redraw the whole view so that we can reflect the changes on the screen.
So now you are going to say invalidate the invalidate method is going to invalidate the whole view and
then we are willing to say request lay out or in other words the reader or the view request out that
it these two lines of code.
Here these two methods are going to do a redesign work for us.
So let's create a comment.
Rita rethrow the whole view.
Now let's create another set here.
So again Puplick void sits.
And then we're going to say text the color a pair of Prentice's.
Again color so text color assignment operator color semicolon and then we are going to redraw the Buza
again to invalidate request late at.
Finally we need to create another setter.
So Puplick void set view takes a pair of Prentice's strange and the name is going to be text.
So we're going to say if you text assignment operator text semicolon and then we are going to say invalidate
request lay out that's it finish.
So we created setters for our instance variables as well as creating getters for our instance variables.
Now we can go inside the main activity class and inside is uncreate Meffert we can create a view object
or we can create of your body but we can see view my view assignment operator find view ID as you can
see here it is not required to cast this object to our view object because already we are creating a
view variable a variable that that is of type view.
So if we take a fine view by ID or that Id dot.
And now we can refer to the idea of our custom view that we declared inside the activity and they made
that example custom view.
So if we're actually going to say it fine we can see that the ID of our Castleview here is custom view.
So let's go to our main activity class and we can put a semicolon here.
Now we say my view that set and click listener new and then view that unclick listener inside this unclick
comfort we can for example created Wassmuss edge.
So you say TOSed make text and the context is going to be main activity that this comma the text is
going to be.
Hello calm moderation.
It's going to be short that show.
So let me create in your line here.
Let's run the app so the app is running on the simulator.
If I click on this view now it says hello.
So let's actually change the color of this text color of this Austin takes color so here in order to
change the color of our text inside our custom view we need to have our reference to our my custom view
class how we're going to do that.
First we need to create a but inside our main activity class mean it is a private my custom view and
the name is going to be my custom view semicolon.
Now we need to go inside is uncreate method in order to initialize our my custom you so we can say my
custom view assignment operator.
Now here we must cast this object to actually a custom view object so that we can see my custom view
find view by ID or thought Id that custom view semicolon.
So let me comment out these lines of code here.
So let me create a multi-line comment here for these actually lines of code for this.
My view variable and the click listener for this my view.
And now we can say my custom view that sets on click click Center new view the unclick listener inside
is unclear.
Meffert we can say my custom view data set text color.
Now we can access this set here that we created inside our my custom view class so we can provide a
color so you can say color dot and we can choose one of these colors.
For example we can say a C on or green or any other colors gray blue just shoes for example white or
yellow.
Let's run the earth and here let's click on this view here.
Now the awesome text here is now yellow.
We can also change the view color we can say or my custom view set view color and we can see color dot
so we can change the view color to Queen Rania.
Now let's click on this view here.
The text is yellow and the view color is now green.
You can also change the color to for example something else for example gray run the app.
Now you can see that we can manipulate our custom view.
We can also do something else.
We can't change the text.
We can say my custom view that sets of view text.
For example we can say hello world.
So as you can see we can also change the text of our view so that's it.
You can now create your own custom views in and through it and let me actually show you the cost at
the official documentation of creating custom views in Android.
So open your browser and Google can search for creating custom views in Android.
And then you will see some links that will actually guide you to this page.
Or you can directly enter this.
You are well inside the search part of your web browser developer that Android dot com slash training
slash custom dash views slash index that HCM and creating custom views.
And here you will find actually lots of tutorials in order to create your own custom views and write.
So thank you very much for watching.
If you have any questions about our custom views about creating custom views in Android please post
the discussion of the course and then I will do my best to answer all of your questions and I'll see
you in the next tutorial.