From the course: Programming for Non-Programmers: Android & Kotlin
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Make the Clear button clear all values
From the course: Programming for Non-Programmers: Android & Kotlin
Make the Clear button clear all values
- [Instructor] The next step is to add the functionality to the Clear button. The Clear button is perhaps the easiest part of the calculator, because all we're doing is resetting the calculator to its default state. To do that, just scroll up and find all of our properties. These are the values that we want to change all of these properties to in the Did Press Clear method. We want to set Last Button Was mode to false, current mode to none, et cetera. The easiest way to do that is to highlight all of this code and select it, press Command or Control C to copy it, and then paste it inside of Did Press Clear. As we talked about earlier in the course, when we're changing the values of variables or properties, we never use the var keyword. Var is for creating a new variable. Since these properties already exist, we remove var and a space, and just change their values here. Let's do that for all four of these. Delete var and a space. Now we reset the properties to their default values. The…
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
-
Connect all of the visual elements to code4m 43s
-
Display tapped numbers in the calculator6m 27s
-
Make the Clear button clear all values2m 3s
-
Set the calculator to add or subtract5m 10s
-
Show the total when the equals button is tapped6m 59s
-
Format the number3m 42s
-
Challenge: Multiplication button53s
-
Solution: Multiplication button3m
-
-