I try to program a game with 12 coins in Android/Kotlin. The coins are made by a TextView and created at runtime. All works fine so far.
fun createCoin(coinNumber: Int) : TextView {
val createdCoin = AppCompatTextView(this)
createdCoin.background = ContextCompat.getDrawable(this, R.drawable.simple_circle)
createdCoin.gravity = Gravity.CENTER
createdCoin.layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT)
createdCoin.text = (coinNumber +1).toString()
createdCoin.textSize = 20F
createdCoin.setTextColor(Color.BLACK)
createdCoin.tag = ??????
return createdCoin
}
But now I need to save 2 more informations with each coin.
- posIndex:Int
- state:coinState
The enum:
enum class coinState{
UNKNOWN,
TRUE,
FALSE,
Up,
DOWN
}
Is there a possibility to store these two informations in an object/class and assign it to the tag in TextView. Or is there another simple way?
Thanks for your help Jan