Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Exercise 6-3 Use anonymous inner classes for event listeners In this exercise, y

ID: 3890349 • Letter: E

Question

Exercise 6-3 Use anonymous inner classes for event listeners In this exercise, you’ll modify the Tip Calculator app that’s presented in this chapter so it uses anonymous inner classes for event listeners. 1. Start Android Studio and open the project named ch06_ex3_TipCalculator. 2. Open the class for the activity and review its code. Note that the activity class implements five listener interfaces. 3. Test the app to make sure the EditText, SeekBar, RadioGroup, and Spinner widgets all work correctly. 4. Modify the code so it uses an anonymous inner class for the OnEditorActionListener. To do that, modify the declaration for the class so it doesn’t implement this interface. Then, modify the argument for the method that sets the listener for the EditText widget so that the argument creates the listener object from an anonymous inner class. 5. Test the app to make sure the EditText widget still works correctly. Repeat steps 4 and 5 for the listeners for the SeekBar, RadioGroup, and Spinner widgets.

The starter file is here:

TipCalculatorActivity

activity_tip_calculator.xml

AndroidManifest.xml

Explanation / Answer

Modified Java Activity File is:

Implementing Event Listeners as Inner Classes

TipCalculatorActivity.java: