Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i get the name of image currently in imageview (Kotlin)? [duplicate]

Tags:

android

kotlin

I'm trying to make a quiz app. I want to get the name of the image currently displayed in the imageview.

for example, if cat.jpeg is displayed in imageview i want to retrive "cat" as a variable.

for example, if cat.jpeg is displayed in imageview i want to retrive "cat" as a variable.

like image 960
Noob Avatar asked Dec 07 '25 07:12

Noob


1 Answers

There's an accessibility feature called "Content Description". It's a text description for people that, for some reason, are not able to see the image. You can have the description of the image on the XML file and get it in you java/kotlin code.

BUT

If the image and the text (description) are connected, they should belong to a "bigger" object. Since you have a Quizz app, you can have a "Question" object with properties like "questionText", "questionImgUrl", "questionImgText", "questionAlternativeA", ....

So, when you open a activity/fragment with a question, you'll be able to load the image with Question.questionImgUrl (for exemple, the cat photo) and load the info you want by calling Question.questionImgText (the string "cat").

like image 161
Filipe Oliveira Avatar answered Dec 08 '25 21:12

Filipe Oliveira



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!