I'm just starting with Kotlin to make Android Apps (it's my first programming language) and I'm using a CountDownTimer. I want to access the p0 parameter globally, but I don't know how to. Here's the code:
class MainActivity : AppCompatActivity() {
var score: Int = 0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
var timeTimer = object : CountDownTimer(10000, 1000) {
override fun onFinish() {
timeView.text = "Time's up!"
}
override fun onTick(p0: Long) {
timeView.text = "Time's left: " + p0/1000
}
}.start()
}
fun point (view: View) {
score++
p0 = p0 + 1000
scoreView.text = "Score: $score"
}
}
Function point is called by clicking a button. The thing I'm trying to achieve is making CountDownTimer longer by 1 second every time a user clicks a button.
This line p0 = p0 + 1000
obviously won't work because p0 is inside another code block. Is there any way to make it globally accessible? I've thought about putting CountDownTimer outside onCreate and just starting it in the onCreate, but I think it still wouldn't work as p0 is still inside CountDownTimer code block.