-1

I need to change an ImageView in Android Studio to display a different image (while the program is running). I didn't find a way to accomplish this in Kotlin yet. Thanks for your time.

MCH170
  • 13
  • 2

1 Answers1

2

You need a reference to the ImageView (for example, using ViewBinding or findViewById), then you can use the method setImageResource, as stated in the documentation

Example:

// declare ImageView reference
var myImageView: ImageView

// in onCreate
myImageView = findViewById(R.id.myImageView)

// change image
myImageView.setImageResource(R.drawable.imageName)
Essay97
  • 648
  • 1
  • 9
  • 24