Home > Articles > Mobile Application Development & Programming

How to Create a Tip Calculator App in Android 6

  • Print
  • + Share This
This chapter from Android 6 for Programmers: An App-Driven Approach, 3rd Edition shows you how to create a Tip Calculator app that calculates and displays the tip and total for a restaurant bill amount. This chapter introduces GridLayout, EditText, SeekBar, Event Handling, NumberFormat, Customizing the App's Theme and Defining App Functionality with Java.
This chapter is from the book

Introducing GridLayout, EditText, SeekBar, Event Handling, NumberFormat, Customizing the App’s Theme and Defining App Functionality with Java

03fig00.jpg

3.1 Introduction

The Tip Calculator app (Fig. 3.1(a)) calculates and displays the tip and total for a restaurant bill amount. As you touch the numeric keypad to enter the bill amount’s digits, the app calculates and displays the tip and total bill amounts for the current tip percentage (15% by default). You specify a tip percentage from 0% to 30% by moving the SeekBar thumb—this updates the displayed tip percentage and recalculates the tip and total. All numeric values are displayed using locale-specific formatting. Figure 3.1(b) shows the app after the user enters the amount 56.32 and changes the tip percentage to 25%.

Fig. 3.1

Fig. 3.1 | Entering the bill total and calculating the tip.

You’ll begin by test-driving the app. Then we’ll overview the technologies you’ll use to create the app. You’ll build the app’s GUI using Android Studio’s layout editor and the Component Tree window. Finally, we’ll present the complete Java code for the app and do a detailed code walkthrough.

Note Regarding the Keyboard in Our Screen Captures

The keypad in Fig. 3.1 may differ, based on your AVD’s or device’s Android version or whether you’ve installed and selected a custom keyboard on your device. We configured our AVD to display the dark keyboard for better contrast in our screen captures. To do so:

  1. Touch the home (home.jpg) icon on your AVD or device.
  2. On the home screen, touch the launcher (launcher.jpg) icon, then open the Settings app.
  3. In the Personal section, touch Language and Input.
  4. On an AVD, touch Android Keyboard (AOSP). On a device touch Google Keyboard—we assume you’re using the standard Android keyboard.
  5. Touch Appearance & layouts, then touch Theme.
  6. Touch Material Dark to change to the keyboard with the dark background.
  • + Share This
  • 🔖 Save To Your Account