Lab 3 Instructions
Lab 3 Instructions - What we'll do in lab!
In Lab 3, together we'll go through the following:
- Going through Lab 3 Slides PDF (customize ArrayAdapter and Fragments)
- Supporting a ListView with items that have multiple views using a custom ArrayAdapter and Using a Fragment to add new cities to ListyCity (customize ArrayAdapter and Fragments code & walkthrough)
Download the Starter code here
Read about Java code conventions (see the Code Conventions (Schoepp) PDF).
Editing existing cities in ListyCity (see the Lab 3 Participation Exercise below for more details)
Lab 3 Participation Exercise
Note: Proper completion of this exercise is considered as part of course participation.
Task: Add functionality to ListyCity to allow editing an existing city. The specifics of the design of this functionality are up to you.
If you could not attend the labs or do not have the code for the updated Lab 3 ListyCity, follow Lab 3 Instructions for ListyCity CustomList and then ListyCity Fragment. You can also download the "Lab 3 Demo" code from eClass.
Your app does not need to look exactly like the screenshots. All that is required is the ability to edit an existing city. You can implement it and make it look like however you want.
Hints: 1. Add setters to your City class so that you can modify its name and province.
- You may need to pass the City object that is clicked in the Activity into the Fragment. One way to do this is to make a constructor for the Fragment that takes in a City, and store the City in the Fragment as an instance variable. If you do this, make sure to also add an empty constructor to the Fragment so you can use it when adding a new City. Another way you can send a City object from the Activity to the Fragment is by adding a "newInstance" method in the Fragment, and use this method to create a new Fragment when editing a City. In this method, you take in a City and store it in the Fragment's Bundle object (if you do this, make sure that your City class implements the "Serializable" interface, so that it can be saved into the Bundle). Later on in your onCreateDialog method, you can access the Bundle using getArguments() and retrieve the City object there. Note that storing data in a Bundle is similar to storing data in an Intent using key-value pairs. (This is the preferred way to do it in Android, because you usually should not have custom constructors for your Fragments. See here for more info).
Example of a newInstance method in AddCityFragment (Hint #3)
You should submit your exercise solution as a zip or tar archive.
Due Date
Friday after the lab at 4PM