From the course: Complete Guide to Android Development with Kotlin for Beginners

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

Load image resources at runtime

Load image resources at runtime

- [Instructor] Currently we're statically setting the Drawable resource. Every time we run the app, the image is going to be the same and it doesn't update. But with the image component, we can load resources at runtime as well. This will allow for the image to change based on user action or a change in data. Let's update our layout so that we can include some interaction from the user. For this, we're going to introduce a switch composable. The first thing we'll need is a variable that will hold the state of the switch. So I'm going to come here to the beginning of our composable function. And then on line number 41, I'm going to create a new variable, which we'll name checked. And this is going to use the remember in line function, we'll be talking more about the remember function later. Next, we're going to have the default value be true. Okay, so by default our switch is going to be in the on state, right? So we have our checked variable. Perfect. Next we're going to add the…

Contents