The add and subtract buttons of the calculator are vital to the calculator functioning properly. See how to create the logic for those buttons in this video.
- [Instructor] The next buttons we're going to set up…are the add and subtract buttons.…So we're going to handle all the code…inside of the change mode method.…So find that in your code.…Mine is on line 54, but of course,…yours might be on a different line.…So, the first thing we need to do when we change the mode,…is we set current mode equal to the mode passed in.…So when the user presses the plus button,…CalculatorMode.Add is set to change mode,…and when they press the minus button,…CalculatorMode.Subtract is set to change mode.…
So let's scroll down.…So we changed the current mode,…so we're storing the mode that the user set,…and then we set lastButtonWasMode equal to true.…Another place where we need to handle the CalculatorMode…is inside of didPressNumber.…Inside of didPressNumber,…we want to see if the last button was mode.…So imagine the user types in a certain amount of numbers,…they type in five, and then they press the plus button…and we run change mode.…
And then they press a six.…What should appear on the screen?…
Author
Released
4/24/2018- Installing Android Studio, Android SDKs, and build tools
- Working with variables
- Using methods
- Connecting interface elements to methods
- Controlling flow with conditional statements, arrays, and loops
- Designing the interface
- Using themes
- Building an Android app from start to finish
Skill Level Beginner
Duration
Views
Related Courses
-
Introduction
-
Welcome1m 2s
-
The finished app1m 20s
-
-
1. Set Up Your Coding Environment
-
The Android Studio interface4m 21s
-
Using the Android Emulator3m 38s
-
2. Programming Building Blocks: Variables
-
How programming works3m 58s
-
Variables3m 33s
-
Using properties2m 53s
-
Enum values5m 30s
-
-
3. Programming Building Blocks: Methods
-
Methods5m 29s
-
Using methods4m 23s
-
Parameter methods7m 44s
-
Connect a button to a method4m 58s
-
Challenge: Methods1m 59s
-
Solution: Methods6m 45s
-
-
4. Programming Building Blocks: Control Flow
-
Conditional statements3m 20s
-
Using conditional statements5m 11s
-
Boolean values6m 24s
-
Arrays1m 45s
-
Using arrays3m 4s
-
Loops3m 42s
-
Using loops4m 25s
-
When statements2m 29s
-
Using when statements8m 6s
-
-
5. Plan and Prepare the App
-
Customize UI objects8m 16s
-
Themes3m 39s
-
Grid layouts3m 29s
-
Finish the user interface2m 48s
-
6. Build a Full Application
-
Format the number3m 42s
-
Conclusion
-
Next steps2m 25s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Set the calculator to add or subtract