Home > Articles > Programming > Java

  • Print
  • + Share This
This chapter is from the book

3.2. Test-Driving the Tip Calculator App

Opening and Running the App

Open the Android Developer Tools IDE and import the Tip Calculator app project. Perform the following steps:

  1. Launching the Nexus 4 AVD. For this test-drive, we’ll use the Nexus 4 smartphone AVD that you configured in the Before You Begin section. To launch the Nexus 4 AVD, select Window > Android Virtual Device Manager to display the Android Virtual Device Manager dialog. Select the Nexus 4 AVD and click Start..., then click the Launch button in the Launch Options dialog that appears.
  2. Opening the Import Dialog. Select File > Import... to open the Import dialog.
  3. Importing the Tip Calculator app’s project. Expand the General node, select Existing Projects into Workspace, then click Next > to proceed to the Import Projects step. Ensure that Select root directory is selected, then click Browse.... In the Browse For Folder dialog, locate the TipCalculator folder in the book’s examples folder, select it and click OK. Ensure that Copy projects into workspace is not selected. Click Finish to import the project. It now appears in the Package Explorer window.
  4. Launching the Tip Calculator app. Right click the TipCalculator project in the Package Explorer window, then select Run As > Android Application to execute Tip Calculator in the AVD.

Entering a Bill Total

Using the numeric keypad, enter 34.56. Just type 3456—the app will position the cents to the right of the decimal point. If you make a mistake, press the delete (deletebutton.jpg) button to erase one rightmost digit at a time. The TextViews under the 15% and the custom tip percentage (18% by default) labels show the tip amount and the total bill for these tip percentages. All the Tip and Total TextViews update each time you enter or delete a digit.

Selecting a Custom Tip Percentage

Use the Seekbar to specify a custom tip percentage. Drag the Seekbar’s thumb until the custom percentage reads 20% (Fig. 3.1(b)). As you drag the thumb, the tip and total for this custom tip percentage update continuously. By default, the Seekbar allows you to select values from 0 to 100, but we specified a maximum value of 30 for this app.

  • + Share This
  • 🔖 Save To Your Account