1
00:00:00,158 --> 00:00:02,539
(upbeat music)

2
00:00:02,539 --> 00:00:05,267
(typing)

3
00:00:05,267 --> 00:00:07,339
Alright, so as I mentioned in the last video,

4
00:00:07,339 --> 00:00:08,875
we've now got a nice group of buttons

5
00:00:08,875 --> 00:00:11,673
that we can drag around as a single object

6
00:00:11,673 --> 00:00:15,193
and what we need to do now is add the IDs of the

7
00:00:15,193 --> 00:00:17,263
remaining six buttons to be changed

8
00:00:17,263 --> 00:00:19,642
and also their text change to show the symbol

9
00:00:19,642 --> 00:00:22,382
for the operation that they're going to be performing

10
00:00:22,382 --> 00:00:24,025
in our calculator app.

11
00:00:24,025 --> 00:00:28,441
So I'm going to start now with, down here, button 11.

12
00:00:28,441 --> 00:00:31,418
We'll make that the divide button.

13
00:00:31,418 --> 00:00:34,392
So we'll call it button divide.

14
00:00:34,392 --> 00:00:36,475
(typing)

15
00:00:37,673 --> 00:00:40,506
The text for that will be a slash.

16
00:00:41,807 --> 00:00:45,025
So next one a button multiply.

17
00:00:45,025 --> 00:00:47,616
(typing)

18
00:00:47,616 --> 00:00:52,199
Multiply. And that's going to be an asterisk or a star.

19
00:00:54,323 --> 00:00:58,740
Next we want a button minus to perform a subtraction.

20
00:01:00,873 --> 00:01:05,290
Button minus. That will be a dash for the minus sign.

21
00:01:06,490 --> 00:01:10,484
We want a button dot so we can enter decimal numbers.

22
00:01:10,484 --> 00:01:14,401
That's going to be numbers with a decimal point

23
00:01:17,569 --> 00:01:20,333
so we can add numbers after the decimal point

24
00:01:20,333 --> 00:01:24,579
so that's button dot and the text for that will be

25
00:01:24,579 --> 00:01:26,246
a period or the dot.

26
00:01:27,631 --> 00:01:30,964
Then we want, also, a button for equals.

27
00:01:32,617 --> 00:01:34,700
(typing)

28
00:01:37,855 --> 00:01:41,522
Button equals and that's going to be equals.

29
00:01:43,479 --> 00:01:46,186
I missed one yet, I need button plus too, of course.

30
00:01:46,186 --> 00:01:48,364
We've got everything else but button plus.

31
00:01:48,364 --> 00:01:49,906
That's for addition, obviously.

32
00:01:49,906 --> 00:01:53,739
So button plus and that will be the plus sign.

33
00:01:54,943 --> 00:01:56,918
Okay, so there's all our buttons.

34
00:01:56,918 --> 00:02:00,869
Now in terms of locations, what we haven't done yet

35
00:02:00,869 --> 00:02:02,694
is we haven't moved button zero.

36
00:02:02,694 --> 00:02:04,567
So let's just move button zero first.

37
00:02:04,567 --> 00:02:07,414
Now button zero comes straight at the top

38
00:02:07,414 --> 00:02:08,889
to the bottom of button one.

39
00:02:08,889 --> 00:02:11,064
So let's start with that.

40
00:02:11,064 --> 00:02:14,296
Straight under button one and its left edge should be

41
00:02:14,296 --> 00:02:16,205
constrained the left edge of button one

42
00:02:16,205 --> 00:02:19,264
as we've done for the other numbers on this site.

43
00:02:19,264 --> 00:02:21,764
So let's go ahead and do that.

44
00:02:23,097 --> 00:02:25,414
We also want to make sure the margin's set to eight,

45
00:02:25,414 --> 00:02:26,821
which it is there.

46
00:02:26,821 --> 00:02:29,722
Which is wrong here because we want to move it over,

47
00:02:29,722 --> 00:02:31,668
so we set that to zero,

48
00:02:31,668 --> 00:02:34,617
so that it fits nicely and snug there.

49
00:02:34,617 --> 00:02:37,215
Alright, so next one is the button dot.

50
00:02:37,215 --> 00:02:39,726
That goes to the right of button zero.

51
00:02:39,726 --> 00:02:42,040
That's this one here. Select that.

52
00:02:42,040 --> 00:02:44,540
Let's go ahead and place that.

53
00:02:48,119 --> 00:02:50,218
We need to do the same baseline constraint

54
00:02:50,218 --> 00:02:52,051
that we've been doing.

55
00:02:57,390 --> 00:02:58,921
The equals sign is next.

56
00:02:58,921 --> 00:03:00,573
The equals is going to be to the right of that

57
00:03:00,573 --> 00:03:03,308
and then plus will be to the right of that.

58
00:03:03,308 --> 00:03:05,808
So, let's do the equals first.

59
00:03:06,676 --> 00:03:08,552
Constrain it to the left.

60
00:03:08,552 --> 00:03:10,947
Set it up from the baseline.

61
00:03:10,947 --> 00:03:14,617
Constrain it to the baseline, like so.

62
00:03:14,617 --> 00:03:17,119
We want another one there, as I mentioned the plus.

63
00:03:17,119 --> 00:03:22,119
I'm going to click on the plus, constrain it to the left.

64
00:03:22,345 --> 00:03:25,428
Then also do the baseline constraint,

65
00:03:27,298 --> 00:03:29,292
to move it up like so.

66
00:03:29,292 --> 00:03:31,252
Alright, so at this point we've got three other buttons

67
00:03:31,252 --> 00:03:33,351
that we need to set now.

68
00:03:33,351 --> 00:03:36,591
We've got button divide. Let's do that one first.

69
00:03:36,591 --> 00:03:38,506
That goes to the right of number nine.

70
00:03:38,506 --> 00:03:42,839
Button divide. Put the constraint on the left there.

71
00:03:45,537 --> 00:03:48,219
Also making sure its still selected.

72
00:03:48,219 --> 00:03:51,386
Do the same for the baseline, like so.

73
00:03:53,608 --> 00:03:57,191
Next we've got the multiply. Let's do that.

74
00:03:58,432 --> 00:04:02,496
That's going to be to the right of six.

75
00:04:02,496 --> 00:04:06,913
Constrain it to the right of six and do the baseline.

76
00:04:08,462 --> 00:04:11,098
Move it to the baseline for six.

77
00:04:11,098 --> 00:04:15,181
The last one, constrain it to the right of three.

78
00:04:16,375 --> 00:04:18,625
This is the minus sign.

79
00:04:18,625 --> 00:04:23,042
We'll do a baseline constraint as well, to the three.

80
00:04:23,999 --> 00:04:26,692
Alright so that's all 16 buttons

81
00:04:26,692 --> 00:04:29,079
that have now been completed.

82
00:04:29,079 --> 00:04:31,095
Now there was a frustrating issue with

83
00:04:31,095 --> 00:04:33,528
previous versions of Android Studio,

84
00:04:33,528 --> 00:04:35,929
but fortunately it seems to have gone.

85
00:04:35,929 --> 00:04:38,705
It's worth mentioning though, partly in case it comes back

86
00:04:38,705 --> 00:04:41,303
and partly because it involves a couple of attributes

87
00:04:41,303 --> 00:04:42,909
that you should know about.

88
00:04:42,909 --> 00:04:45,854
I'm going to select one of the buttons,

89
00:04:45,854 --> 00:04:48,472
in my case I'm going to select the minus button.

90
00:04:48,472 --> 00:04:49,574
That was already selected

91
00:04:49,574 --> 00:04:51,351
cause that was the last one we moved.

92
00:04:51,351 --> 00:04:53,499
You want to expand out the attributes

93
00:04:53,499 --> 00:04:57,580
and I'm going to click on the expanded attributes,

94
00:04:57,580 --> 00:05:00,663
and scroll down here until you get to

95
00:05:03,856 --> 00:05:06,572
mean height and mean width.

96
00:05:06,572 --> 00:05:11,436
Now, by default, mean width used to be set to 88dp,

97
00:05:11,436 --> 00:05:13,489
and that caused the width to keep resetting

98
00:05:13,489 --> 00:05:15,364
if you tried to make the button narrower,

99
00:05:15,364 --> 00:05:17,497
but fortunately you can see here that it's not set

100
00:05:17,497 --> 00:05:19,007
and it's no longer the case.

101
00:05:19,007 --> 00:05:20,916
But if you happen to get problems with widgets

102
00:05:20,916 --> 00:05:23,465
not resizing or resetting after you resize them,

103
00:05:23,465 --> 00:05:25,491
then check out these.

104
00:05:25,491 --> 00:05:28,381
Mean width and mean height in the expanded attributes

105
00:05:28,381 --> 00:05:30,599
to make sure they're not causing you problems.

106
00:05:30,599 --> 00:05:32,672
To a lesser extent, keep an eye on the

107
00:05:32,672 --> 00:05:36,404
max width and max height attributes as well.

108
00:05:36,404 --> 00:05:40,491
I'm not going to change the width of the buttons manually.

109
00:05:40,491 --> 00:05:41,867
because the text that could take

110
00:05:41,867 --> 00:05:44,576
could be resized independently.

111
00:05:44,576 --> 00:05:46,806
You can select large fonts for the display

112
00:05:46,806 --> 00:05:49,123
which could make the text look a bit ugly

113
00:05:49,123 --> 00:05:51,636
if the buttons don't resize as well.

114
00:05:51,636 --> 00:05:54,537
So we want to leave our buttons set to wrap content.

115
00:05:54,537 --> 00:05:56,616
Now, you could change the size to fixed

116
00:05:56,616 --> 00:05:59,160
then size them to 48dp, say,

117
00:05:59,160 --> 00:06:02,245
but bear in mind that font size isn't under

118
00:06:02,245 --> 00:06:03,780
your complete control.

119
00:06:03,780 --> 00:06:07,513
Wrap_content uses smaller button size where possible

120
00:06:07,513 --> 00:06:11,258
you want to change the mean width attribute to 48dp.

121
00:06:11,258 --> 00:06:12,438
We're going to go ahead and do that, and again,

122
00:06:12,438 --> 00:06:14,539
I've got everything selected here.

123
00:06:14,539 --> 00:06:16,299
I've got my minus sign selected here,

124
00:06:16,299 --> 00:06:18,940
so I'm going to come over here to mean width

125
00:06:18,940 --> 00:06:22,273
and I'm going to change that now to 48dp

126
00:06:24,181 --> 00:06:25,514
and press enter.

127
00:06:26,626 --> 00:06:30,716
You can see the buttons moved or sized down by doing that.

128
00:06:30,716 --> 00:06:32,274
Now it would get a bit tedious

129
00:06:32,274 --> 00:06:33,964
changing each button individually,

130
00:06:33,964 --> 00:06:36,214
but what we can do is select them all

131
00:06:36,214 --> 00:06:38,451
and change them all in one go.

132
00:06:38,451 --> 00:06:40,260
Now, I've already shown you how to select all the buttons

133
00:06:40,260 --> 00:06:41,690
by dragging over them.

134
00:06:41,690 --> 00:06:43,668
Another way which can be useful if you've got other

135
00:06:43,668 --> 00:06:47,918
widgets in the way, is to right click button minus,

136
00:06:49,625 --> 00:06:51,502
and then I can actually choose Select

137
00:06:51,502 --> 00:06:53,669
and then Select Same Type.

138
00:06:58,409 --> 00:07:00,314
You can see that's automatically selected

139
00:07:00,314 --> 00:07:01,834
all the other buttons.

140
00:07:01,834 --> 00:07:04,986
Changing the mean width attribute now will set it

141
00:07:04,986 --> 00:07:08,864
for all buttons, but what's happened to mean width?

142
00:07:08,864 --> 00:07:10,760
You can see it's actually disappeared.

143
00:07:10,760 --> 00:07:13,102
Seems to have vanished from the attributes.

144
00:07:13,102 --> 00:07:15,517
Android Studio tries to be helpful,

145
00:07:15,517 --> 00:07:18,262
and once you've changed an attribute it moves up

146
00:07:18,262 --> 00:07:20,741
to the top of the attributes list.

147
00:07:20,741 --> 00:07:23,119
Now, this list is sort of alphabetical,

148
00:07:23,119 --> 00:07:25,221
but arranged in two sections.

149
00:07:25,221 --> 00:07:28,833
Attributes that you changed appear alphabetically at the top

150
00:07:28,833 --> 00:07:32,595
then the list starts again alphabetically

151
00:07:32,595 --> 00:07:33,797
with all the other widgets.

152
00:07:33,797 --> 00:07:37,130
So if you scroll back up to the top now,

153
00:07:38,133 --> 00:07:41,469
you can see we've got our mean width over here

154
00:07:41,469 --> 00:07:46,010
and we're going to go over here and change that to 48dp.

155
00:07:46,010 --> 00:07:48,785
Press enter and you can see

156
00:07:48,785 --> 00:07:51,432
all buttons have now been resized.

157
00:07:51,432 --> 00:07:52,936
The other thing you want to do here is

158
00:07:52,936 --> 00:07:55,960
just make sure the layout width and layout height

159
00:07:55,960 --> 00:07:58,409
is set to wrap content before unselecting them.

160
00:07:58,409 --> 00:08:00,985
You can see here that is the case.

161
00:08:00,985 --> 00:08:02,809
Now if you're setting the same properties

162
00:08:02,809 --> 00:08:05,776
for many widgets at once, what I've shown here

163
00:08:05,776 --> 00:08:07,512
makes life a lot easier.

164
00:08:07,512 --> 00:08:10,264
Not all properties can be set for groups of widgets

165
00:08:10,264 --> 00:08:12,914
at the same time, so although this is a useful feature,

166
00:08:12,914 --> 00:08:14,320
there are times when you just have

167
00:08:14,320 --> 00:08:16,521
to set each one individually.

168
00:08:16,521 --> 00:08:20,254
Just click in anywhere now, any blank part of the layout,

169
00:08:20,254 --> 00:08:22,087
to select the buttons.

170
00:08:23,561 --> 00:08:26,532
Before I move on to add the forgotten widgets,

171
00:08:26,532 --> 00:08:29,696
let's have another look at the componentry to the left.

172
00:08:29,696 --> 00:08:32,462
Although it generally makes no different what order

173
00:08:32,462 --> 00:08:35,980
the widgets appear in here, you can put them

174
00:08:35,980 --> 00:08:37,633
in a more logical order,

175
00:08:37,633 --> 00:08:39,527
reflecting their position on the screen

176
00:08:39,527 --> 00:08:41,609
by dragging them up and down to sort them

177
00:08:41,609 --> 00:08:43,089
into an order that makes sense.

178
00:08:43,089 --> 00:08:45,558
It'll also be easy to find the individual digit buttons

179
00:08:45,558 --> 00:08:48,425
to select them if they appear in numerical order

180
00:08:48,425 --> 00:08:50,211
and they should probably be all together.

181
00:08:50,211 --> 00:08:51,769
So I'm going to drag the widgets around now

182
00:08:51,769 --> 00:08:53,650
just to reorder them.

183
00:08:53,650 --> 00:08:57,800
We've got button zero, I'm going to move button one up here.

184
00:08:57,800 --> 00:09:00,541
We've got buttons zero through nine.

185
00:09:00,541 --> 00:09:02,520
We've got the result text at the top.

186
00:09:02,520 --> 00:09:06,337
Then we've got divide, multiply, minus.

187
00:09:06,337 --> 00:09:08,670
Let's actually move plus up.

188
00:09:11,103 --> 00:09:13,490
Then we've got dot and equals.

189
00:09:13,490 --> 00:09:15,337
Now in this app the order makes no difference

190
00:09:15,337 --> 00:09:17,996
to the way the layout works, but it does reflect

191
00:09:17,996 --> 00:09:21,206
the order that the widgets appear in the xml.

192
00:09:21,206 --> 00:09:23,783
Now if you're using nested layouts then make sure

193
00:09:23,783 --> 00:09:27,075
you don't drag your widget out of its container.

194
00:09:27,075 --> 00:09:28,736
Now that may not mean much now,

195
00:09:28,736 --> 00:09:31,383
but we'll be looking at nested layouts later.

196
00:09:31,383 --> 00:09:33,484
Also, be careful with linear layouts,

197
00:09:33,484 --> 00:09:36,369
because the ordering of the widgets does matter then.

198
00:09:36,369 --> 00:09:38,383
We're going to be looking at nested layouts

199
00:09:38,383 --> 00:09:41,727
and linear layouts later in the course.

200
00:09:41,727 --> 00:09:44,897
Time to suddenly remember that we need two more widgets.

201
00:09:44,897 --> 00:09:47,576
A text view to display the operation

202
00:09:47,576 --> 00:09:51,600
and an edit text to allow new numbers to be entered.

203
00:09:51,600 --> 00:09:53,868
Although you could drag the buttons out of the way

204
00:09:53,868 --> 00:09:56,869
to make more room, there's really no need.

205
00:09:56,869 --> 00:09:58,699
What I'm going to do is place a text view

206
00:09:58,699 --> 00:10:02,628
and assign number in a text in a space below the buttons,

207
00:10:02,628 --> 00:10:06,084
then delete the vertical constraint on button seven.

208
00:10:06,084 --> 00:10:07,798
While I've still got plenty of room on the screen

209
00:10:07,798 --> 00:10:09,721
I'm going to set the left edge of the text view

210
00:10:09,721 --> 00:10:12,113
to be constrained to the left edge of the layout

211
00:10:12,113 --> 00:10:16,622
and it's right edge to the left edge of the edit text.

212
00:10:16,622 --> 00:10:18,212
Let's actually start doing some of this.

213
00:10:18,212 --> 00:10:22,805
So we'll start with the text view, we'll drag one out

214
00:10:22,805 --> 00:10:24,541
and put it down at the bottom of the screen here.

215
00:10:24,541 --> 00:10:25,724
Anywhere, it doesn't really matter.

216
00:10:25,724 --> 00:10:28,613
We also want that sign number in a text we talked about

217
00:10:28,613 --> 00:10:31,280
as well. Just put it down there.

218
00:10:35,684 --> 00:10:37,396
So again, I'm going to set the left edge

219
00:10:37,396 --> 00:10:39,141
of the text view to be constrained

220
00:10:39,141 --> 00:10:40,252
to the left edge of the layout.

221
00:10:40,252 --> 00:10:42,335
So let's start with that,

222
00:10:44,021 --> 00:10:48,938
and the right edge to be to the left edge of the edit text.

223
00:10:53,698 --> 00:10:56,675
I'm also going to constrain the top edge of the text view

224
00:10:56,675 --> 00:10:59,590
to the top of the new edit text.

225
00:10:59,590 --> 00:11:02,487
The top edge is going to be constrained to the top edge

226
00:11:02,487 --> 00:11:04,941
of the edit text, of the new edit text that is.

227
00:11:04,941 --> 00:11:06,619
I'm going to click on that

228
00:11:06,619 --> 00:11:09,168
and you can see that's moved down now.

229
00:11:09,168 --> 00:11:11,752
I want to change the right edge,

230
00:11:11,752 --> 00:11:14,167
and it might involve me moving this fractionally over here

231
00:11:14,167 --> 00:11:15,670
so we can see what we're doing.

232
00:11:15,670 --> 00:11:19,461
We want the right edge of the text view now to be

233
00:11:19,461 --> 00:11:23,597
constrained to the left edge of the edit text.

234
00:11:23,597 --> 00:11:25,893
You can see I've already done that so that's set up.

235
00:11:25,893 --> 00:11:29,263
If I come back and have a look up here in the inspector,

236
00:11:29,263 --> 00:11:32,213
text view here, we've got a constraint on the left edge

237
00:11:32,213 --> 00:11:36,880
of the layout to the right constraint from the text view

238
00:11:38,308 --> 00:11:40,307
is now constrained to the left of the edit view

239
00:11:40,307 --> 00:11:42,439
and the top is also constrained to the top

240
00:11:42,439 --> 00:11:44,805
of the new edit text as well.

241
00:11:44,805 --> 00:11:49,610
We should probably be using the baseline constraint here,

242
00:11:49,610 --> 00:11:51,939
but I've used top so that I can show you another way

243
00:11:51,939 --> 00:11:53,866
to change it later.

244
00:11:53,866 --> 00:11:56,691
I can now constrain the top of this new edit text

245
00:11:56,691 --> 00:11:58,555
to the bottom of the first one we added

246
00:11:58,555 --> 00:12:01,817
called result, and then constrain the top of button seven

247
00:12:01,817 --> 00:12:03,758
to the bottom of this one.

248
00:12:03,758 --> 00:12:07,154
So when I constrain the top of the new edit text

249
00:12:07,154 --> 00:12:10,352
to the bottom of the old one, you can see,

250
00:12:10,352 --> 00:12:13,754
when I do that, the text through an edit text combination

251
00:12:13,754 --> 00:12:16,364
obscure button seven and that makes it difficult

252
00:12:16,364 --> 00:12:18,909
to change the constraint on button seven.

253
00:12:18,909 --> 00:12:21,219
It's certainly possible, but what I'm going to do is

254
00:12:21,219 --> 00:12:22,241
do it the other way around.

255
00:12:22,241 --> 00:12:25,161
So I'm going to undo that change using command z on a Mac

256
00:12:25,161 --> 00:12:27,637
or control z on a PC.

257
00:12:27,637 --> 00:12:30,217
You can see that undoes the last one.

258
00:12:30,217 --> 00:12:33,042
Now what we'll do instead is delete the top constraint

259
00:12:33,042 --> 00:12:34,745
on button seven.

260
00:12:34,745 --> 00:12:36,591
Go over here to button seven and select it then

261
00:12:36,591 --> 00:12:38,611
delete the constraint.

262
00:12:38,611 --> 00:12:40,276
Then what we're going to do is drag a constraint

263
00:12:40,276 --> 00:12:42,071
from the top of button seven to the bottom

264
00:12:42,071 --> 00:12:43,821
of the new edit text.

265
00:12:45,563 --> 00:12:47,480
We're going to do that.

266
00:12:50,343 --> 00:12:52,251
You can see then that the entire square of buttons

267
00:12:52,251 --> 00:12:53,958
moves as a single block and that's

268
00:12:53,958 --> 00:12:56,470
because they're all ultimately constrained to button seven.

269
00:12:56,470 --> 00:12:58,015
So that's pretty cool.

270
00:12:58,015 --> 00:13:00,118
Whatever we constrain button seven to,

271
00:13:00,118 --> 00:13:01,877
the rest of the buttons will follow.

272
00:13:01,877 --> 00:13:06,811
Half of them, or in my case you can see half of them,

273
00:13:06,811 --> 00:13:08,306
are probably off the bottom of the screen,

274
00:13:08,306 --> 00:13:09,255
but don't worry about that.

275
00:13:09,255 --> 00:13:11,332
What we can now do is drag a constraint

276
00:13:11,332 --> 00:13:14,442
from the top of this new edit text to the bottom

277
00:13:14,442 --> 00:13:15,953
of the result edit text

278
00:13:15,953 --> 00:13:19,289
and everything should come back right.

279
00:13:19,289 --> 00:13:21,544
You can see that it's come back.

280
00:13:21,544 --> 00:13:23,673
It should be obvious by now that you don't position widgets

281
00:13:23,673 --> 00:13:25,753
on the screen by dragging them into place.

282
00:13:25,753 --> 00:13:28,458
You do it by creating constraints.

283
00:13:28,458 --> 00:13:30,388
It's these constraints that determine where

284
00:13:30,388 --> 00:13:33,664
the widgets will appear when you run the app.

285
00:13:33,664 --> 00:13:36,897
I should really have assigned more informative IDs

286
00:13:36,897 --> 00:13:38,777
to these two new widgets first,

287
00:13:38,777 --> 00:13:40,554
but I wanted to show you what happens when

288
00:13:40,554 --> 00:13:44,491
you change an ID once the widgets used by something else,

289
00:13:44,491 --> 00:13:47,829
either by constraints in the layout or in code.

290
00:13:47,829 --> 00:13:51,063
I'm going to first start with this new ID,

291
00:13:51,063 --> 00:13:52,340
which I've already got selected,

292
00:13:52,340 --> 00:13:53,964
but click it if it's not selected.

293
00:13:53,964 --> 00:13:58,214
You're going to change the ID of that to new number

294
00:13:59,244 --> 00:14:00,161
New number.

295
00:14:03,276 --> 00:14:07,216
When I press enter I get a dialogue asking if I wanted

296
00:14:07,216 --> 00:14:10,809
to update all xml references and R references,

297
00:14:10,809 --> 00:14:12,911
Java R field references.

298
00:14:12,911 --> 00:14:15,101
Normally I'd answer yes to this,

299
00:14:15,101 --> 00:14:17,591
anywhere the old ID was used it would be

300
00:14:17,591 --> 00:14:20,604
automatically updated with the new ID.

301
00:14:20,604 --> 00:14:22,761
Now that's pretty cool, so why wouldn't you want

302
00:14:22,761 --> 00:14:24,474
to answer yes?

303
00:14:24,474 --> 00:14:27,117
Well if you'd already created the code that used this

304
00:14:27,117 --> 00:14:29,486
layout it would be referring to buttons like

305
00:14:29,486 --> 00:14:31,736
button two or button nine.

306
00:14:33,339 --> 00:14:35,330
Now if you decided to redesign this layout

307
00:14:35,330 --> 00:14:37,709
by deleting all the buttons and recreating them,

308
00:14:37,709 --> 00:14:41,385
button nine may be assigned to the divide button.

309
00:14:41,385 --> 00:14:43,633
When you rename it you don't want Android Studio

310
00:14:43,633 --> 00:14:46,343
updating the references to button nine in your code

311
00:14:46,343 --> 00:14:49,089
to use a new button ID button divide.

312
00:14:49,089 --> 00:14:52,353
So it's a useful feature, but it's also handy

313
00:14:52,353 --> 00:14:55,132
to be able to prevent it from updating everything.

314
00:14:55,132 --> 00:14:57,702
Of course, I could have also avoided any

315
00:14:57,702 --> 00:15:01,494
potential problem by not using names like button nine.

316
00:15:01,494 --> 00:15:04,676
I should probably have abbreviated button to BTN

317
00:15:04,676 --> 00:15:06,899
or something like that so that there was no chance

318
00:15:06,899 --> 00:15:09,204
of a conflict with the default IDs

319
00:15:09,204 --> 00:15:11,216
the Android Studio assigns.

320
00:15:11,216 --> 00:15:14,031
That's worth bearing in mind as it can cause you problems,

321
00:15:14,031 --> 00:15:17,885
so don't start the ID of a widget with the widget name.

322
00:15:17,885 --> 00:15:21,230
I'm going to answer yes to this dialogue.

323
00:15:21,230 --> 00:15:24,221
Then I'm going to go over to the new text view.

324
00:15:24,221 --> 00:15:28,388
We're going to change the ID of that to operation.

325
00:15:29,653 --> 00:15:31,028
Press enter there.

326
00:15:31,028 --> 00:15:33,044
We're almost done at this point.

327
00:15:33,044 --> 00:15:35,587
I'd like the new number edit text widget to be centred

328
00:15:35,587 --> 00:15:37,706
in the layout and the operation text view

329
00:15:37,706 --> 00:15:40,468
to be centred in the space to its left.

330
00:15:40,468 --> 00:15:44,532
Once that's done I'll look at moving all the buttons right

331
00:15:44,532 --> 00:15:46,719
so they're centred in the layout.

332
00:15:46,719 --> 00:15:50,144
First you should really deal with those two text widgets.

333
00:15:50,144 --> 00:15:51,371
Did I say you?

334
00:15:51,371 --> 00:15:55,417
Well that sounds like a mini challenge.

335
00:15:55,417 --> 00:15:58,986
The challenge here is to change the horizontal size

336
00:15:58,986 --> 00:16:01,907
of the new number widget to wrap_content,

337
00:16:01,907 --> 00:16:02,968
if it isn't already,

338
00:16:02,968 --> 00:16:06,209
so that it can expand to store the numbers that are entered,

339
00:16:06,209 --> 00:16:08,104
then set constraints to centre it

340
00:16:08,104 --> 00:16:10,074
horizontally in the layout.

341
00:16:10,074 --> 00:16:13,169
When that's done, centre the operation text view

342
00:16:13,169 --> 00:16:15,600
in the space to the left of new number.

343
00:16:15,600 --> 00:16:17,825
Its size both horizontally and vertically

344
00:16:17,825 --> 00:16:20,435
should be set to wrap_content.

345
00:16:20,435 --> 00:16:21,784
So that's the challenge.

346
00:16:21,784 --> 00:16:22,874
I'm going to end the video here,

347
00:16:22,874 --> 00:16:24,344
so see how you go with that.

348
00:16:24,344 --> 00:16:26,930
In the next video I'll go through and post the solution.

349
00:16:26,930 --> 00:16:29,180
See you in the next video.

