Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

  1. posIndex:Int
  2. 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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
236 views
Welcome To Ask or Share your Answers For Others

1 Answer

Way to save 2 object without any effort and additional classes :

tag = Pair(5, coinState.DOWN)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...