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

Update display from new data - Android Tutorial

From the course: Android Development Essential Training: App Architecture with Kotlin

Start my 1-month free trial

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