Lab 3 Instructions
Lab 3: More Android
1. Getting Started
- Fork and clone this repository and open the
/codefolder in Android Studio. - You'll find a basic
ListyCityapp that displays a static list of cities and provinces.
2. Demo Instructions
During the lab demo, we'll implement "Add City" functionality:
- Review Lab 3 Slides
- Follow along with Lab 3 Instructions
- Read about Code Conventions (see the Kotlin Code Conventions PDF).
- By the end, you'll have implemented the ability to add new cities to the list.
3. Lab 3 Participation Exercise
Task
- Add functionality to
ListyCityto allow editing existing cities. The design implementation is flexible and up to your creativity. - Update the
README.mdand theLICENSE.mdwith your details.
Example Implementation

Note: Your app does NOT need to look exactly like the screenshots. The only requirement is the ability to edit an existing city.
4. Implementation Tips
1. City Class Updates
- The starter code uses a
Citydata class withvalproperties:
data class City(
val name: String,
val province: String
)
Since name and province use val, they cannot be changed directly after a City object is created
To edit a city, create a new City object with the updated values and replace the old city in the list
Example:
val updatedCity = City(
name = newCityName,
province = newProvinceName
)
2. Choose Your Implementation
Recommended Approach:
- Track which City object is selected
- Store the edited city name and province in text fields
- Create a new City object with the updated values
- Replace the selected city in the list
Example Code
One approach is to add an updateCity() function to CityRepository:
fun updateCity(oldCity: City, updatedCity: City) {
val index = _cities.indexOf(oldCity)
if (index != -1) {
_cities[index] = updatedCity
}
}
Compose Hints
- Use state to track the selected city:
var selectedCity by remember { mutableStateOf<City?>(null) }
- A city row can be made selectable using Modifier.clickable { ... }
- Text fields can be reused to enter the updated city name and province
- Use a callback such as onUpdateCity(oldCity, updatedCity) to send the edit action upward
5. Submission
[!CAUTION] Make sure to commit and push your code to the GitHub repository before the deadline!
Once you completed, please go to Canvas and submit your Lab 3 GitHub repository link.
Due Date
Friday after the Thursday lab at 5 PM