In this video we look at an Android App that uses Jetpack Compose to create a "Composable" set of checkboxes. The code creates a function that generates a set of checkboxes from an array of choices. The function is not within SetContent and doesn't rely on "global" state variables -- so that state variables as well a function to set the variables must be passed to the checkbox-generating method. Because the user can choose more than option, the state variable was a mutable list of integers corresponding to the indices of the user's choices. A further complication was that a mutable list does not yield a "re-composition." Therefore, the following kluge was employed -- a second state variable of a simple string was also sent to the method. The display of the user's choices used both the mutable list of integers and the string. The indices are what we desire, but the string forces the re-composition.
- 8 ай бұрын
Android Compose Demo: Set of Checkboxes
- Рет қаралды 193
Пікірлер: 1