MP2: Add Place Activity

Created By: Geoffrey Challen
/ Updated: 2022-11-11

Let's wrap up our work on allowing a user to add their favorite place to the map! In this lesson, we'll discuss how to complete the UI work required to bring this new feature to fruition. Let's do it!

Add Place Activity

At this point our AddPlaceActivity.java is blank. Let's fix that, load the layout that we've provided for this activity, and discuss where to define the unique ID for this client.

Show how to load the layout so the activity displays something. Also add a Unique ID to the application file.

Handling Button Events

Next, let's get some practice integrating our layout with our activity. Specifically, we'll add an action to the Cancel button allowing the user to return to the map overview without adding a favorite place—for example, if they mis-clicked on the map, or changed their mind about where their favorite place is.

This will allow us to establish a general pattern for the rest of this part of the project, in demonstrating how to create links between the components that define the layout and the functionality provided in our Java code.

Wire up the cancel button so that it works properly and sends the user back to the main activity. Identify the steps involved: locating the ID in the layout, loading that component using findViewById, and adding event handlers as needed.

Finishing Up

To wrap up, let's discuss what's left to do and create a plan in comments. Note that we are expecting you to do a bit of work on your own to complete the checkpoint! But we'll provide some hints that should point you in the right direction.

Discuss how to complete the rest of the checkpoint, focusing on how to gather various pieces of required information.

To describe the desired behavior of this activity in a bit more detail. When the save button is pressed, a new favorite place on the map should be created, with the latitute and longitude passed to the AddPlaceActivity when it was launched, a description provided by the user in the appropriate text box, and the ID defined in FavoritePlacesApplication. After the call to create the favorite place completes successfully, the AddPlaceActivity should return to the MainActivity so that the user can view the updated map.

There may be other functionality that you want to add to the AddPlaceActivity to make it more usable—for example, provide a default "Enter your description here..." text in the description input, not create new favorite places if the description is empty, or show an error message if the call to create the favorite place fails. You should be able to add some of these additional features and still pass the test suite. However, the test suite does not test these optional capabilities.

No Homework for This Lesson

As a reminder, on lessons where we focus on the machine project we will not assign a homework problem! However, the lesson will usually focus on helping you complete a particular part of the MP test suite, and so we encourage you to spend time on that in lieu of a homework problem.

Right now your goal should be to finish MP2 by completing the final test case. Good luck! If you get stuck, find us for help on the help site or forum.

MP2 Scores

More Practice

Need more practice? Head over to the practice page.