This is my button class implementation:
package com.example.myproject
import android.R
import android.content.Context
import android.graphics.Color
import android.os.CountDownTimer
import android.util.Log
import android.widget.ImageView
import kotlin.properties.Delegates
data class MyButton() : androidx.appcompat.widget.AppCompatButton(context) {
init {
this.text = "test"
this.setOnClickListener { v ->
Log.d("CLICK", "click")
}
object: CountDownTimer(_time, 1000) {
override fun onTick(millisUntilFinished: Long) {
var rnd = (0..20).random()
if (rnd < 10) {
this.setBackgroundResource(R.drawable.notebook) //notebook
} else {
this.setBackgroundResource(R.drawable.desktop_pc) //desktop PC
}
}
override fun onFinish() {
exitProcess(-1)
}
}.start()
}
}
So I want to, based on some random generator, put whether notebook image or desktop PC image on my button. This is my res folder:
res > drawable > notebook.png, desktop_pc.png
Both images I put there using copy-paste. But the problem is that the method R.drawable cannot find these two files, it's not possible to load them from this folder. Where is the problem?