1
00:00:00,850 --> 00:00:03,000
Hello this is Martez al-Qadi.

2
00:00:03,090 --> 00:00:11,050
And in this story you are going to provide get Herods for our instance variables inside are my custom

3
00:00:11,050 --> 00:00:12,390
view class.

4
00:00:12,490 --> 00:00:18,520
So let's go inside the curly braces of our class here before getting curly brace of RMI like us of your

5
00:00:18,520 --> 00:00:25,570
class let's create a comment getters for instance variables.

6
00:00:25,580 --> 00:00:29,900
So now let's say let's actually take a look at our instance variables here.

7
00:00:29,930 --> 00:00:31,550
The first one is the view color.

8
00:00:31,790 --> 00:00:35,170
So let's say that we have public.

9
00:00:35,290 --> 00:00:42,260
Remember I told you our Make sure to always declare your guitarist as Puplick because you may want to

10
00:00:42,260 --> 00:00:50,330
use these get is inside another class so public and the return value of this method here is going to

11
00:00:50,330 --> 00:00:52,050
be integer.

12
00:00:52,070 --> 00:00:56,470
The name is going to be get View color.

13
00:00:56,840 --> 00:01:01,950
Put a pair of perhaps this here and then open and close this Meffert by using these curly braces return

14
00:01:03,060 --> 00:01:06,780
view color semicolon.

15
00:01:07,090 --> 00:01:11,840
Now it's time to actually create another getter for our second instance variable.

16
00:01:12,070 --> 00:01:17,510
So let's say you look at our instance variables here we have the text color and the view text.

17
00:01:17,590 --> 00:01:19,720
So let's say we have Puplick

18
00:01:25,160 --> 00:01:32,890
text Cotliar a pair of practices and here you going to return the color semicolon.

19
00:01:33,220 --> 00:01:36,490
And finally we have the takes.

20
00:01:36,510 --> 00:01:48,270
So again Puplick screen Get view text return view text.

21
00:01:48,520 --> 00:01:56,570
So now that we have the getters for instance variables it's time to create the setters for instance

22
00:01:56,570 --> 00:01:57,430
variables.

23
00:01:58,440 --> 00:02:09,880
So we have Puplick voit set view color of her Apprentice's and let's create a primitive integer and

24
00:02:09,880 --> 00:02:12,310
it is going to be color.

25
00:02:12,350 --> 00:02:20,210
So if you are going to say that you have to view color assignment operator color semicolon.

26
00:02:20,590 --> 00:02:22,830
And now we need to read there.

27
00:02:22,830 --> 00:02:25,090
Our view is this is very important.

28
00:02:25,090 --> 00:02:33,100
Now we are actually sitting and the view colored view or we are actually changing an attribute of our

29
00:02:33,100 --> 00:02:34,020
custom view.

30
00:02:34,210 --> 00:02:40,490
So we are going to redraw the whole view so that we can reflect the changes on the screen.

31
00:02:40,960 --> 00:02:48,860
So now you are going to say invalidate the invalidate method is going to invalidate the whole view and

32
00:02:48,860 --> 00:02:58,840
then we are willing to say request lay out or in other words the reader or the view request out that

33
00:02:58,890 --> 00:03:01,150
it these two lines of code.

34
00:03:01,150 --> 00:03:07,310
Here these two methods are going to do a redesign work for us.

35
00:03:08,210 --> 00:03:10,490
So let's create a comment.

36
00:03:10,520 --> 00:03:15,330
Rita rethrow the whole view.

37
00:03:15,330 --> 00:03:17,320
Now let's create another set here.

38
00:03:17,340 --> 00:03:22,570
So again Puplick void sits.

39
00:03:22,800 --> 00:03:29,350
And then we're going to say text the color a pair of Prentice's.

40
00:03:29,680 --> 00:03:39,950
Again color so text color assignment operator color semicolon and then we are going to redraw the Buza

41
00:03:39,950 --> 00:03:45,190
again to invalidate request late at.

42
00:03:45,300 --> 00:03:48,190
Finally we need to create another setter.

43
00:03:48,210 --> 00:04:01,470
So Puplick void set view takes a pair of Prentice's strange and the name is going to be text.

44
00:04:01,520 --> 00:04:10,540
So we're going to say if you text assignment operator text semicolon and then we are going to say invalidate

45
00:04:11,410 --> 00:04:14,590
request lay out that's it finish.

46
00:04:15,070 --> 00:04:23,400
So we created setters for our instance variables as well as creating getters for our instance variables.

47
00:04:23,710 --> 00:04:32,140
Now we can go inside the main activity class and inside is uncreate Meffert we can create a view object

48
00:04:32,170 --> 00:04:40,540
or we can create of your body but we can see view my view assignment operator find view ID as you can

49
00:04:40,540 --> 00:04:47,500
see here it is not required to cast this object to our view object because already we are creating a

50
00:04:47,500 --> 00:04:51,010
view variable a variable that that is of type view.

51
00:04:51,010 --> 00:04:56,160
So if we take a fine view by ID or that Id dot.

52
00:04:56,350 --> 00:05:01,850
And now we can refer to the idea of our custom view that we declared inside the activity and they made

53
00:05:01,860 --> 00:05:03,370
that example custom view.

54
00:05:03,400 --> 00:05:09,680
So if we're actually going to say it fine we can see that the ID of our Castleview here is custom view.

55
00:05:10,000 --> 00:05:14,600
So let's go to our main activity class and we can put a semicolon here.

56
00:05:14,620 --> 00:05:24,370
Now we say my view that set and click listener new and then view that unclick listener inside this unclick

57
00:05:24,370 --> 00:05:29,800
comfort we can for example created Wassmuss edge.

58
00:05:29,890 --> 00:05:39,900
So you say TOSed make text and the context is going to be main activity that this comma the text is

59
00:05:39,900 --> 00:05:41,180
going to be.

60
00:05:41,560 --> 00:05:43,940
Hello calm moderation.

61
00:05:44,020 --> 00:05:47,140
It's going to be short that show.

62
00:05:47,190 --> 00:05:48,980
So let me create in your line here.

63
00:05:49,080 --> 00:05:52,770
Let's run the app so the app is running on the simulator.

64
00:05:52,770 --> 00:05:56,620
If I click on this view now it says hello.

65
00:05:56,650 --> 00:06:03,240
So let's actually change the color of this text color of this Austin takes color so here in order to

66
00:06:03,240 --> 00:06:11,630
change the color of our text inside our custom view we need to have our reference to our my custom view

67
00:06:11,640 --> 00:06:14,040
class how we're going to do that.

68
00:06:14,130 --> 00:06:23,670
First we need to create a but inside our main activity class mean it is a private my custom view and

69
00:06:23,670 --> 00:06:26,020
the name is going to be my custom view semicolon.

70
00:06:26,310 --> 00:06:33,150
Now we need to go inside is uncreate method in order to initialize our my custom you so we can say my

71
00:06:33,150 --> 00:06:35,490
custom view assignment operator.

72
00:06:35,490 --> 00:06:44,400
Now here we must cast this object to actually a custom view object so that we can see my custom view

73
00:06:44,940 --> 00:06:52,180
find view by ID or thought Id that custom view semicolon.

74
00:06:52,740 --> 00:06:55,970
So let me comment out these lines of code here.

75
00:06:56,010 --> 00:07:02,340
So let me create a multi-line comment here for these actually lines of code for this.

76
00:07:02,340 --> 00:07:06,530
My view variable and the click listener for this my view.

77
00:07:06,970 --> 00:07:18,010
And now we can say my custom view that sets on click click Center new view the unclick listener inside

78
00:07:18,030 --> 00:07:18,660
is unclear.

79
00:07:18,670 --> 00:07:25,220
Meffert we can say my custom view data set text color.

80
00:07:25,230 --> 00:07:32,910
Now we can access this set here that we created inside our my custom view class so we can provide a

81
00:07:32,910 --> 00:07:37,880
color so you can say color dot and we can choose one of these colors.

82
00:07:37,880 --> 00:07:50,880
For example we can say a C on or green or any other colors gray blue just shoes for example white or

83
00:07:50,880 --> 00:07:52,330
yellow.

84
00:07:52,380 --> 00:07:57,240
Let's run the earth and here let's click on this view here.

85
00:07:57,510 --> 00:08:00,840
Now the awesome text here is now yellow.

86
00:08:01,020 --> 00:08:14,660
We can also change the view color we can say or my custom view set view color and we can see color dot

87
00:08:15,900 --> 00:08:20,160
so we can change the view color to Queen Rania.

88
00:08:20,160 --> 00:08:22,210
Now let's click on this view here.

89
00:08:22,260 --> 00:08:26,630
The text is yellow and the view color is now green.

90
00:08:26,660 --> 00:08:38,550
You can also change the color to for example something else for example gray run the app.

91
00:08:38,590 --> 00:08:42,840
Now you can see that we can manipulate our custom view.

92
00:08:43,060 --> 00:08:45,580
We can also do something else.

93
00:08:45,580 --> 00:08:47,960
We can't change the text.

94
00:08:48,100 --> 00:08:55,780
We can say my custom view that sets of view text.

95
00:08:55,830 --> 00:08:59,510
For example we can say hello world.

96
00:08:59,550 --> 00:09:04,480
So as you can see we can also change the text of our view so that's it.

97
00:09:04,590 --> 00:09:11,420
You can now create your own custom views in and through it and let me actually show you the cost at

98
00:09:11,430 --> 00:09:17,080
the official documentation of creating custom views in Android.

99
00:09:17,520 --> 00:09:23,660
So open your browser and Google can search for creating custom views in Android.

100
00:09:23,940 --> 00:09:27,800
And then you will see some links that will actually guide you to this page.

101
00:09:27,870 --> 00:09:29,910
Or you can directly enter this.

102
00:09:29,910 --> 00:09:35,700
You are well inside the search part of your web browser developer that Android dot com slash training

103
00:09:35,970 --> 00:09:42,120
slash custom dash views slash index that HCM and creating custom views.

104
00:09:42,450 --> 00:09:49,820
And here you will find actually lots of tutorials in order to create your own custom views and write.

105
00:09:49,860 --> 00:09:51,590
So thank you very much for watching.

106
00:09:51,780 --> 00:09:57,880
If you have any questions about our custom views about creating custom views in Android please post

107
00:09:57,870 --> 00:10:03,810
the discussion of the course and then I will do my best to answer all of your questions and I'll see

108
00:10:03,810 --> 00:10:05,170
you in the next tutorial.

