1
00:00:00,360 --> 00:00:05,820
Hire everyone in this tutorial I run a touch about menus in Android.

2
00:00:05,820 --> 00:00:11,380
So just click on this start in your Android studio project and for the application name just type in

3
00:00:11,510 --> 00:00:21,150
an app 48 and then click on next and here choose API 16 Android 4.1 Jelly Bean and then click on next

4
00:00:21,840 --> 00:00:24,800
and here choose empty activity next.

5
00:00:25,050 --> 00:00:27,110
And here click on finish.

6
00:00:28,040 --> 00:00:32,190
So now as you can see our project is actually created.

7
00:00:32,330 --> 00:00:35,660
So now it's actually double click on this and this folder here.

8
00:00:35,900 --> 00:00:39,650
And now I want to actually create a directory for my menu.

9
00:00:39,650 --> 00:00:40,270
OK.

10
00:00:40,340 --> 00:00:45,350
So just right click on this race for that new and then click on directory.

11
00:00:45,620 --> 00:00:50,860
And for the name of our directory just type in here menu and then click on OK.

12
00:00:51,170 --> 00:00:53,510
So here I have this menu directory.

13
00:00:53,510 --> 00:01:01,130
So now I want to actually put our I took the XML file inside this menu for the menu that I want to use

14
00:01:01,130 --> 00:01:02,890
in my application.

15
00:01:03,170 --> 00:01:08,660
So just right click on the menu here new and then click on menu resource find.

16
00:01:08,750 --> 00:01:09,830
OK.

17
00:01:10,460 --> 00:01:15,040
And as you can see here now you need to specify our name for our menu.

18
00:01:15,230 --> 00:01:25,040
So here I am just typing menu underlined made ok because I want this menu to be inside the inside the

19
00:01:25,040 --> 00:01:28,270
main activity for my activity underline main that I examine.

20
00:01:28,370 --> 00:01:34,220
So this is going to be the name menu underline main the source said should be made as you can see here

21
00:01:34,580 --> 00:01:37,130
and the directory name must be menu.

22
00:01:37,220 --> 00:01:38,050
OK.

23
00:01:38,210 --> 00:01:39,040
And then click on it.

24
00:01:39,050 --> 00:01:39,780
OK.

25
00:01:40,160 --> 00:01:45,230
So here inside this menu directory I have this menu underline made that examen.

26
00:01:45,260 --> 00:01:45,860
OK.

27
00:01:46,070 --> 00:01:48,780
And here is my menu underlined minute example.

28
00:01:48,920 --> 00:01:51,920
So here I can actually create create some items.

29
00:01:52,160 --> 00:01:54,070
So here I can just open tag.

30
00:01:54,350 --> 00:01:57,420
And as you can see here we have this group and we have this item.

31
00:01:57,440 --> 00:02:02,640
So just select this item here and then our present space key on your keyboard.

32
00:02:02,990 --> 00:02:08,090
And now I can actually for example specify an ID for my item.

33
00:02:08,210 --> 00:02:12,800
For example the ID is going to be at sign Plus Id slash.

34
00:02:12,980 --> 00:02:21,950
And here the is for example settings and here are just a present interview on your keyboard now I want

35
00:02:21,960 --> 00:02:25,180
to specify a title for this idea.

36
00:02:25,220 --> 00:02:35,110
For example I can just type in title and the title is going to be settings OK for this menu.

37
00:02:35,250 --> 00:02:37,570
This is the title.

38
00:02:37,880 --> 00:02:40,770
And now I need to actually close this item.

39
00:02:40,770 --> 00:02:49,410
This item tag so i can just put this closing tag here and now as you can see I closed this item back.

40
00:02:49,440 --> 00:02:55,800
So now I have this item here and now inside this main activity class we need to actually overwrite some

41
00:02:55,800 --> 00:02:59,090
of the methods that are related to the menu.

42
00:02:59,190 --> 00:03:05,850
So the first one is on create options menu as you can see here.

43
00:03:05,910 --> 00:03:09,420
So just select it and press Enter key on your keyboard.

44
00:03:09,420 --> 00:03:15,690
So as you can see here this is our Meffert the first of it and the second one is when the user clicks

45
00:03:15,690 --> 00:03:18,630
on one of those items inside the menu.

46
00:03:18,840 --> 00:03:26,320
So the second one is on item as you can see here on options item selected as you can see here.

47
00:03:26,340 --> 00:03:32,360
So just select the second one on options item selected and then press on Enter key on your keyboard.

48
00:03:32,610 --> 00:03:36,180
So here I have these two methods that are related to the menu.

49
00:03:36,180 --> 00:03:39,890
So now let's actually run our project and see what happens.

50
00:03:40,020 --> 00:03:46,890
So now as you can see our application is running on this emulator and we cannot see the menu inside

51
00:03:46,950 --> 00:03:48,510
this action bar here.

52
00:03:48,510 --> 00:03:50,470
So remember that this is the action board.

53
00:03:50,540 --> 00:03:51,040
OK.

54
00:03:51,180 --> 00:03:59,160
And here is the name of our application at 48 and here at the right side I want to see the menu actually

55
00:03:59,460 --> 00:04:00,770
the menu button.

56
00:04:00,900 --> 00:04:06,030
So in order to do that let's actually delete this line of code here on here as you can see inside this

57
00:04:06,170 --> 00:04:07,510
uncreate options menu.

58
00:04:07,620 --> 00:04:11,850
It is a line of code and inside this method to actually put my own logic here.

59
00:04:11,850 --> 00:04:18,460
So here inside this uncreate options menu I can just type in the GET menu inflator.

60
00:04:18,510 --> 00:04:18,990
OK.

61
00:04:19,200 --> 00:04:25,760
So when this object here in order to actually put our menu are inside our action bar.

62
00:04:25,770 --> 00:04:26,290
OK.

63
00:04:26,340 --> 00:04:30,680
So as you can see here this is an action bar and I want to actually put the menu here.

64
00:04:31,050 --> 00:04:33,710
So here I need to put this method here.

65
00:04:33,780 --> 00:04:37,020
Get menu inflator dot inflate.

66
00:04:37,860 --> 00:04:40,530
And here we need to actually specify two arguments.

67
00:04:40,530 --> 00:04:45,630
The first one is the menu XML file that we created in our project.

68
00:04:45,630 --> 00:04:51,620
So as you can see here in our project an insight is this fall that I have this race and have this a

69
00:04:51,630 --> 00:04:54,570
menu directory and insight is menu.

70
00:04:54,570 --> 00:04:58,690
I have this exemplified menu underline main that exemption.

71
00:04:58,800 --> 00:05:01,590
So I need to refer to that XML file.

72
00:05:01,590 --> 00:05:08,070
I just need to type in here are dots menu that may menu underline main.

73
00:05:08,290 --> 00:05:15,480
OK comma and for the second argument I need to refer to this menu object that we receive as an argument

74
00:05:15,840 --> 00:05:18,100
from the Smurfette uncreate options menu.

75
00:05:18,210 --> 00:05:20,630
So here I can just type in menu.

76
00:05:20,670 --> 00:05:25,410
So now let's actually as you can see here this Smurfette returns a boolean value.

77
00:05:25,530 --> 00:05:31,920
So we need to return a boolean value so I can just type in here return to semicolon.

78
00:05:32,160 --> 00:05:35,280
So let's run our project now and see what happens.

79
00:05:35,280 --> 00:05:41,730
So now as you can see our application is running on this emulator here and here as you can see inside

80
00:05:41,730 --> 00:05:45,580
this inside this action bar I have this menu button here.

81
00:05:45,600 --> 00:05:50,510
So if I click on it and now we can see this item settings for this menu.

82
00:05:50,820 --> 00:05:51,420
OK.

83
00:05:51,420 --> 00:05:58,140
So inside this menu underline the example I created an item and I assigned an ID to this item.

84
00:05:58,260 --> 00:06:01,720
And here is the title of this item settings for menu.

85
00:06:01,860 --> 00:06:05,320
And here we can see these settings for this menu here.

86
00:06:05,700 --> 00:06:11,040
So let's go back to our main activity the double file here and now I want to actually do something when

87
00:06:11,040 --> 00:06:16,410
the user clicks on these settings for this menu but in here on this item.

88
00:06:16,410 --> 00:06:16,900
OK.

89
00:06:17,070 --> 00:06:20,340
So in order to do that let me actually delete this line of code here.

90
00:06:20,400 --> 00:06:26,160
And as you can see we have this method and this if it returns a value of a boolean and this and the

91
00:06:26,160 --> 00:06:29,130
name of this if it is an optional item selected.

92
00:06:29,190 --> 00:06:34,350
And we have an argument of type menu item and the name of this argument is item.

93
00:06:34,350 --> 00:06:43,200
So here we can specify that up which one of the items is actually selected by actually using this argument.

94
00:06:43,200 --> 00:06:51,200
So in order to do that here I can just get the ID of the items that are inside this menu underline that

95
00:06:51,200 --> 00:06:51,730
exemption.

96
00:06:51,750 --> 00:06:58,340
So as you can see here I have this item here and the I.D. of this item is sitting as you can see here.

97
00:06:58,440 --> 00:07:04,590
So inside this main activity that I here and inside is an options item selected in order to get that

98
00:07:04,650 --> 00:07:07,530
ID again it just create an int variable.

99
00:07:07,540 --> 00:07:14,340
Int ID the name of this variable is the assignment operator and that here and refer to the name of this

100
00:07:14,340 --> 00:07:16,430
item that is of type menu item.

101
00:07:16,430 --> 00:07:17,220
Right.

102
00:07:17,220 --> 00:07:21,770
So I can't just type in an item that gets item ID.

103
00:07:21,870 --> 00:07:23,850
So now I have that by the.

