58.7 Completing the Example
All that remains is to implement a mechanism for calling the getCurrentTime() method and displaying the result to the user. As is now customary, Android Studio will have created a template activity_main.xml file for the activity containing only a TextView. Load this file into the Layout Editor tool and, using Design mode, select the TextView component and change the ID to myTextView. Add a Button view beneath the TextView and change the text on the button to read “Show Time”, extracting the text to a string resource named show_time. On completion of these changes, the layout should resemble that illustrated in Figure 58-1. If any constraints are missing, click on the Infer Constraints button in the Layout Editor toolbar.
Figure 58-1
Complete the user interface design by selecting the Button and configuring the onClick property to call a method named showTime.
Finally, edit the code in the MainActivity.java file to implement the...