У меня есть эта интерактивная игра с 2 кнопками и 1 изображением, где изображения хранятся на карте. Текущее изображение - var currentImageDrawable
, поэтому при нажатии кнопки изображение меняется вместе с currentImageVariable
. Но поскольку я добавил TextView
, просто чтобы изменить текст, когда отображается конкретное изображение, к сожалению, оно не меняется. Это просто остается в первом тексте, который «Начать игру?».
import com.example.thegame.R.drawable.*
var tv = findViewById<TextView>(R.id.textView)
var currentImageDrawable = menu
data class Choice(val choice1: Int, val choice2: Int)
val choicesMap = mapOf(
menu to Choice(door1, menu),
door1 to Choice(door_inside, door_back),
door_inside to Choice(door_inside2, door_inside2_1),
door_back to Choice(door_back2, door_back2_1)
)
buttonYes.setOnClickListener {
currentImageDrawable = choicesMap[currentImageDrawable]!!.choice1
imageView.setImageResource(currentImageDrawable)
}
buttonNo.setOnClickListener {
currentImageDrawable = choicesMap[currentImageDrawable]!!.choice2
imageView.setImageResource(currentImageDrawable)
if (currentImageDrawable== menu) {
finishAffinity()
}
}
if (currentImageDrawable== menu) {
tv.setText("Start the game?") }
else if (currentImageDrawable== door1) {
tv.setText("Open the door?") }
else {
tv.setText("")
}
/*
when (currentImageDrawable) {
menu -> tv.setText("start the game?")
door1 -> tv.setText("open the door?")
else -> tv.text = ("")
}
*/