Welcome back.
In this chapter, we are going to build a calculator and I want to show you what the calculator can
do and what it can do.
So there are some limitations here.
And the idea behind this calculator is that you learn to build complex UI, so to speak.
So a complex user interface, which means the graphical user interface that we can see all of those
buttons positioned correctly with the right distance to each other and so forth, because, as you can
see, they are all equally distant to each other.
And detectives are all the same size and so forth, so this is something that you have to take into
consideration when building such a way that it looks good and it's really a rather boring example.
Of course, calculators are super boring, in my opinion, because it's just an app that everybody has
on his phone anyways.
But it's a very good example for building such a UI.
And it's also something that you probably get quite a lot at university.
So if you ever go to university and have it there or programming, then it's very likely that they will
ask you to build a calculator or you build a calculator at one point and university.
And because this is a rather early stage in the course, we're not going to use third party libraries
for this.
We're just going to use basic code.
And that will also limit the functionality of our calculator because we cannot use super large numbers
and we cannot use super precise numbers either.
So dividing is going to be a huge problem for our calculator.
For example, if we divide a value here, you can see this is the result that we get.
And now if I want to do any additional calculations afterwards, it won't work because the application
is limited to 12 values here or to 12 digits, so to speak.
All right.
And if I clear and then I do some other.
Operations, you can see I can do multiple operations after another.
It's no issue.
And all of them work fine, but as soon as I have a huge number or a very long entry, as you can see
here, then it gets limited.
So now I cannot do anything with it anymore.
At that point, I have to clear my calculator.
So that's just a limitation of the data types that we have as well.
So, for example, the doubled in DeLong's, all of those data types that we're using, they are limited
to a certain amount of digits and that's what we have limited to to just 12 to make sure that everything
is still going to work.
Of course, we have to be careful, dividing by zero is always a problem, so we get the result of infinity.
All right, so at this point, you can try to build this, you are yourself and many things could go
wrong, but that's no problem.
If you want, just go ahead and try to build this.
You are just an advice from my side.
Use linear layouts, so don't use the constraint layouts where you just drag stuff in there.
Of course you can do that and it might work as well, but it's going to be a pain to make everything
equally far from each other and really well positioned.
So I would really recommend to go ahead and use linear layouts.
So how are we going to do it?
Is the whole thing.
The whole app is going to be within a linear layout.
Then we have a TextField here at the top, which takes quite some space.
Then we have a linear layout for all the buttons here.
So for one row or each row will be a linear layout which contains the individual buttons.
And then we have a linear layout which contains all of the different rows.
So that's pretty much it.
In order to get to double width here for a button, what you can do is you can use a functionality called
weight.
So layout underscore weight.
That's the property that you have to work with.
So, for example, the zero button has a layout weight of two, all of the individual buttons, they
have a layout weight of one and the equal sign.
You could think that it has a layout way to four, but it actually also has a layout weight of one because
it's the only element in that role here.
We can see there are three elements of the zero has a weight of two and each of those buttons has the
weight of one.
So the zero will be as big as or as wide as two other buttons.
The same goes for the individual rows.
So each row is equally high.
So they all have a layout weight of one.
So they are equally poll or equally high.
All right.
So this is just a little side note.
If you want, you can go ahead and try it yourself.
If you do, then good luck.
And if you don't want to do it, you just want to watch the videos, then of course, you can do so
as well.
And then the next video, I'm going to show you how to build that where I will show you one way of building
it.
Of course, there are multiple different ways of building this UI and maybe you have a even nicer version
or something at that.
So I hope you enjoyed this little exercise and this little app and see you in the next video.