From the course: Android Development Essential Training: App Architecture with Kotlin
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Update display from new data - Android Tutorial
From the course: Android Development Essential Training: App Architecture with Kotlin
Update display from new data
- [Instructor] I've previously described how to wrap business logic in companion object functions in Kotlin classes, now I'll demonstrate how to use that code from a main activity class. In my main activity, I've already declared an array of image view objects, that are referencing the die images in the activity layout. I've also created a reference variable that's pointing to this text view object, that's the text at the top of the screen. When the user clicks the floating action button in the lower-right corner, I want to roll the dice using the code in the DiceHelper class. So I'll place this code inside my fabClickHandler function. First I'll create a variable that I'll name dice and I'll get its value by calling DiceHelper.rollDice. So now I have a randomized integer array, now I'm going to loop through the image view objects and set the images one die at a time. I'm going to use an iteration loop that starts with a value of zero and goes until the size of the image view's array…
Contents
-
-
-
-
(Locked)
Work with synthetic view bindings5m 10s
-
(Locked)
Get view references with findViewById()4m 53s
-
(Locked)
Handle view events with lambdas5m 26s
-
(Locked)
Create companion object functions6m 16s
-
(Locked)
Update display from new data4m 47s
-
(Locked)
Restore state after orientation change7m 10s
-
(Locked)
Add a ViewModel to an activity4m 43s
-
(Locked)
Subscribe to changes in LiveData values7m 57s
-
(Locked)
-
-
-