CS 3180 Mobile Application Development

Week 6 Wednesday: Lists and Dialogs Demo

CS 3180 Mobile Application Development

Week 6 Wednesday: Lists and Dialogs Demo
CS 3180 Mobile Application Development

Demo Goals

  1. Build a LazyColumn list
  2. Add a top app bar with actions
  3. Use AlertDialog for data entry
Week 6 Wednesday: Lists and Dialogs Demo
CS 3180 Mobile Application Development

Part 1: Contact List UI

Week 6 Wednesday: Lists and Dialogs Demo
CS 3180 Mobile Application Development

Step 1: Data Model

data class Contact(
    val id: String,
    val name: String,
    val role: String
)
Week 6 Wednesday: Lists and Dialogs Demo
CS 3180 Mobile Application Development

Step 2: Sample Data

val initialContacts = listOf(
    Contact("c1", "Maria Lopez", "Volunteer Lead"),
    Contact("c2", "Eli Chen", "Score Runner"),
    Contact("c3", "Noah Patel", "Check-in"),
    Contact("c4", "Ava Johnson", "Volunteer")
)
Week 6 Wednesday: Lists and Dialogs Demo
CS 3180 Mobile Application Development

Step 3: List Screen Skeleton

@Composable
fun ContactsScreen() {
    var contacts by remember { mutableStateOf(initialContacts) }

    LazyColumn(
        contentPadding = PaddingValues(16.dp),
        verticalArrangement = Arrangement.spacedBy(8.dp)
    ) {
        items(contacts, key = { it.id }) { contact ->
            ContactRow(contact)
        }
    }
}
Week 6 Wednesday: Lists and Dialogs Demo
CS 3180 Mobile Application Development

Step 4: Row UI

@Composable
fun ContactRow(contact: Contact) {
    Surface(
        modifier = Modifier.fillMaxWidth(),
        tonalElevation = 2.dp,
        shape = RoundedCornerShape(12.dp)
    ) {
        Row(
            modifier = Modifier.padding(12.dp),
            horizontalArrangement = Arrangement.SpaceBetween
        ) {
            Column {
                Text(contact.name, style = MaterialTheme.typography.titleMedium)
                Text(contact.role, style = MaterialTheme.typography.bodyMedium)
            }
        }
    }
}
Week 6 Wednesday: Lists and Dialogs Demo
CS 3180 Mobile Application Development

Part 2: App Bar and Actions

Week 6 Wednesday: Lists and Dialogs Demo
CS 3180 Mobile Application Development

Step 5: Scaffold + TopAppBar

@Composable
fun ContactsScreen() {
    var contacts by remember { mutableStateOf(initialContacts) }

    Scaffold(
        topBar = {
            TopAppBar(
                title = { Text("Volunteer Contacts") },
                actions = {
                    IconButton(onClick = { /* open dialog */ }) {
                        Icon(Icons.Default.Add, contentDescription = "Add")
                    }
                }
            )
        }
    ) { padding ->
        LazyColumn(
            modifier = Modifier.padding(padding),
            contentPadding = PaddingValues(16.dp),
            verticalArrangement = Arrangement.spacedBy(8.dp)
        ) {
            items(contacts, key = { it.id }) { contact ->
                ContactRow(contact)
            }
        }
    }
}
Week 6 Wednesday: Lists and Dialogs Demo
CS 3180 Mobile Application Development

Part 3: Dialog for Adding Contacts

Week 6 Wednesday: Lists and Dialogs Demo
CS 3180 Mobile Application Development

Step 6: Dialog State

var showDialog by remember { mutableStateOf(false) }
var name by remember { mutableStateOf("") }
var role by remember { mutableStateOf("") }
Week 6 Wednesday: Lists and Dialogs Demo
CS 3180 Mobile Application Development

Step 7: AlertDialog UI

if (showDialog) {
    AlertDialog(
        onDismissRequest = { showDialog = false },
        title = { Text("Add Contact") },
        text = {
            Column {
                OutlinedTextField(
                    value = name,
                    onValueChange = { name = it },
                    label = { Text("Name") }
                )
                OutlinedTextField(
                    value = role,
                    onValueChange = { role = it },
                    label = { Text("Role") }
                )
            }
        },
        confirmButton = {
            TextButton(onClick = { /* add contact */ }) {
                Text("Add")
            }
        },
        dismissButton = {
            TextButton(onClick = { showDialog = false }) {
                Text("Cancel")
            }
        }
    )
}
Week 6 Wednesday: Lists and Dialogs Demo
CS 3180 Mobile Application Development

Step 8: Add Contact Action

TextButton(onClick = {
    if (name.isNotBlank() && role.isNotBlank()) {
        val newContact = Contact(
            id = "c${contacts.size + 1}",
            name = name,
            role = role
        )
        contacts = contacts + newContact
        name = ""
        role = ""
        showDialog = false
    }
}) {
    Text("Add")
}
Week 6 Wednesday: Lists and Dialogs Demo
CS 3180 Mobile Application Development

Wrap-Up

Week 6 Wednesday: Lists and Dialogs Demo
CS 3180 Mobile Application Development

What You Built Today

  • LazyColumn contact list
  • Top app bar with add action
  • Dialog with input fields
Week 6 Wednesday: Lists and Dialogs Demo
CS 3180 Mobile Application Development

Friday Lab Preview

  • Android CodeLab: Build a Scrollable List
  • Practice with LazyColumn and images
Week 6 Wednesday: Lists and Dialogs Demo

SPEAKER NOTES: Today is a build-focused demo. We’ll create a contacts list for tournament volunteers and add a dialog to add new contacts.

SPEAKER NOTES: We’ll work from an empty Compose screen to a usable contact list with add/delete actions.

SPEAKER NOTES: We’ll start with data and list rendering.

SPEAKER NOTES: Simple model. We’ll use a stable ID for keys.

SPEAKER NOTES: This gives us something to render before we wire inputs.

SPEAKER NOTES: We’ll use `items` with a stable key. Later we’ll move state into a ViewModel.

SPEAKER NOTES: Use a `Surface` to give the row a card-like feel without adding a full Card.

SPEAKER NOTES: We need navigation and quick actions. Add a top app bar with an add button.

SPEAKER NOTES: Introduce `Scaffold` for app bars and ensure list content respects padding.

SPEAKER NOTES: We’ll capture user input with a dialog and update the list.

SPEAKER NOTES: Three small pieces of state: dialog visibility and two text fields.

SPEAKER NOTES: Use two text fields inside the dialog. Validate inputs before adding.

SPEAKER NOTES: This is a simple example. Later, we’ll use a ViewModel and proper ID generation.

SPEAKER NOTES: Connect today’s demo to Friday’s CodeLab on scrollable lists.

SPEAKER NOTES: Remind students that the same patterns apply to scorecards, team lists, and announcements.

SPEAKER NOTES: Encourage students to bring questions about list performance and dialog UX.