Customize the Player List Items

Kotlin and Android Development featuring Jetpack — by Michael Fazio (26 / 125)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Add AI Spinner to Player List Items | TOC | Create Another ViewModel (Game) 👉

Again, the Pick Players screen is currently functional as is, but once you get some real users on the app, there’s bound to be some confusion. Nothing is telling users what happens when you check or uncheck the check box for a player or what that switch at the end means. Disabling unchecked items gives users an indication what they’re doing when they check the box since they’ve seen forms like this before.

For the <SwitchCompat> tag, we can change the on/off states from just being a generic-looking switch to human and AI icons. This way people will be able to quickly tell what’s going on with each control without the need for a bunch of text on the screen. First up is the <CheckBox> and the android:enabled attribute.

Allow the Items to Be Enabled and Disabled

We want to disable any players that aren’t included in the game as determined by the check box in each row. This serves two purposes: it tells the user what that check box does and avoids setting up players that aren’t going to be used. To disable views in a player list item, we will use the android:enabled attribute which will reference player.isIncluded. The <EditText>, <Spinner>, and <SwitchCompat> tags will all contain android:enabled”@{player.isIncluded}”…

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.