Search code examples
androidkotlinbooleanonclicklistenerdata-class

Boolean turns into int number 904 in Kotlin


I'm working on a quiz app for my project at university, and I'm trying to save button and boolean that states if the answer is correct or not in data class and save all buttons in a temporary list so I can add onclick listener for all of them later. But when I'm trying to access boolean value, it just turns into number 904. Here's my code regarding these buttons.

val ansBtnList: MutableList<ButtonDataClass> = mutableListOf()
--------------------------------------------------------------
val ans = ButtonDataClass(Button(this), quizToShow.getValue(planets[0]).answers[i].isRight)
--------------------------------------------------------------
ansBtnList.add(ans)
--------------------------------------------------------------
for (i in 0..3) {
        ansBtnList[i].btn.setOnClickListener { Log.d(null, ansBtnList[i].btn.right.toString()) }
    }

Thanks in advance!

EDIT: ButtonDataClass code:

data class ButtonDataClass (var btn: Button, var right: Boolean)

Solution

  • It's not the right that you think it is. btn is the button. The button has a right field that is related to its coordinate on screen. You should try ansBtnList[i].right.toString() instead.