I am starting to work with the Kotlin fun extensions. I've created some that are working correctly for me, but I have one with the ImageView context that doesn't work and I don't understand why.
The extension function is this:
fun ImageView.imageCardAssignation(imageSelected: Int): Int {
when(imageSelected){
0 -> R.drawable.card_amazon
1 -> R.drawable. card_card
2 -> R.drawable. card_house
}
return imageSelected
}
The idea is that depending on the number (Int) that you pass as a parameter, assign one image or another to the ImageView.
I invoke it as follows:
vb.selectImage.setImageResource (imageCardAssignation (0))
But the ID indicates the error:
- none of the following candidates is applicable because os receiver type mismatch
I think the context has to be ImageView
What am I doing wrong?
Thank you very much and greetings.