0

Kotlin: Set Image SRC

Hello. So I am trying to set the source of an ImageButton (Android Studio) using Kotlin. I looked it up, and found I should just use setImageResource(image) However, I get the error: Unresolved Reference: setImageResource How can I fix it? Thanks!

29th Aug 2018, 8:25 PM
Paul Grasser
Paul Grasser - avatar
5 Respostas
+ 4
setImageResource is a method of ImageButton class then you have to call it on that object type... You did it?
30th Aug 2018, 12:48 AM
KrOW
KrOW - avatar
+ 1
Yes. val btn = imgbtn as ImageButton btn.setImageResource("@drawable/image") This gives me an error (I did import ImageButton
30th Aug 2018, 7:01 AM
Paul Grasser
Paul Grasser - avatar
0
Hmmm... Dont knowing much kotlin system, i can only think that something in configuration is wrong... This happen with other android components?
30th Aug 2018, 7:22 AM
KrOW
KrOW - avatar
0
KrOW no.
30th Aug 2018, 8:03 AM
Paul Grasser
Paul Grasser - avatar
0
Paul Grasser Its very hard figure out what is the problem.... I think that something go bad with environment (android studio or gradle)... Try to clear cache of AS and of Gradle and rebuild all (search on google)
30th Aug 2018, 8:25 AM
KrOW
KrOW - avatar