Home > Articles > Programming > Java

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

3.7. Wrap-Up

In this chapter, you created your first interactive Android app—the Tip Calculator. We overviewed the app’s capabilities, then you test-drove it to calculate standard and custom tips based on the bill amount entered. You followed detailed step-by-step instructions to build the app’s GUI using the Android Developer Tools IDE’s Graphical Layout editor, Outline window and Properties window. We also walked through the code of the Activity subclass MainActivity, which defined the app’s functionality.

In the app’s GUI, you used a GridLayout to arrange the views into rows and columns. You displayed text in TextViews and received input from an EditText and a SeekBar.

The MainActivity class required many Java object-oriented programming capabilities, including classes, objects, methods, interfaces, anonymous inner classes and inheritance. We explained the notion of inflating the GUI from its XML file into its screen representation. You learned about Android’s Activity class and part of the Activity lifecycle. In particular, you overrode the onCreate method to initialize the app when it’s launched. In the onCreate method, you used Activity method findViewById to get references to each of the views that the app interacts with programmatically. You defined an anonymous inner class that implements the TextWatcher interface so the app can calculate new tips and totals as the user changes the text in the EditText. You also defined an anonymous inner class that implements the OnSeekBarChangeListener interface so the app can calculate a new custom tip and total as the user changes the custom tip percentage by moving the SeekBar’s thumb.

Finally, you opened the AndroidManifest.xml file in the IDE’s Android Manifest editor to specify that the MainActivity supports only portrait orientation and that the MainActivity should always display the keypad.

Using the IDE’s Graphical Layout editor, Outline window, Properties window and Android Manifest editor enabled you to build this app without manipulating the XML in the project’s resource files and AndroidManifest.xml file.

In the next chapter, we introduce collections while building the Twitter® Searches app. Many mobile apps display lists of items. You’ll do this by using a ListActivity containing a ListView that’s bound to an ArrayList<String>. You’ll also store app data as user preferences and learn how to launch the device’s web browser to display a web page.

  • + Share This
  • 🔖 Save To Your Account