From the course: Programming for Non-Programmers: Android & Kotlin
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Display tapped numbers in the calculator
From the course: Programming for Non-Programmers: Android & Kotlin
Display tapped numbers in the calculator
- [Male Voice] Now it's time to actually start writing the code for the calculator that we can actually test. 'Cause up to this point, all that we've done so far is prepare. And now we're ready to start writing the actual logic of the application. Scroll down to the very bottom of your code, and find didPressNumber, so that's that method right here. In my code it's on line 50. What we're going to do first is handle the code that happens when the user presses the numeric buttons. Remember, we set that up previously, and each button sends the appropriate number to didPressNumber. So when we press zero, then didPressNumber receives the number zero. The one button sends the number of one, et cetera. So, inside a didPressNumber, I'll tab in there. And what we're going to do first is take the number that was pressed, and convert it into a string. The reason we're doing that is because we need to store that number as a string inside of our label string property. We'll use label string to put…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
Set up properties and methods6m 15s
-
(Locked)
Connect all of the visual elements to code4m 43s
-
(Locked)
Display tapped numbers in the calculator6m 27s
-
(Locked)
Make the Clear button clear all values2m 3s
-
(Locked)
Set the calculator to add or subtract5m 10s
-
(Locked)
Show the total when the equals button is tapped6m 59s
-
(Locked)
Format the number3m 42s
-
(Locked)
Challenge: Multiplication button53s
-
(Locked)
Solution: Multiplication button3m
-
-