CountDownTimer: как я могу увеличить вместо уменьшения таймера - PullRequest
0 голосов
/ 08 ноября 2019

Я просто хочу увеличить CountDownTimer вместо уменьшения. я знаю, я должен изменить «mTimeInMillis», но я не знаю, как и где. не могли бы вы мне помочь. спасибо Код: "

private var startTime = 100000L
private var increaseTime = +10000L
private var mTimer : CountDownTimer? = null
private var mTimerRunnning = false
private var mTimeInMillis = startTime

private fun updateCountDownText(){
    var minutes  = (mTimeInMillis/1000).toInt()/60 //  div.Millis in Sekunden,dann div. in Minuten
    var seconds  = (mTimeInMillis/1000).toInt()%60  // div.Millis in Sekunden
    var timeFormatted : String = String.format("%02d:%02d", minutes, seconds)
    tvTime.text = timeFormatted
}


private fun startTimer() {
    // mTimer = new CountDownTimer(timeLeftInMillis,1000){// ANDROID
    if(!mTimerRunnning){
        mTimer?.start()
    }

       mTimer = object  : CountDownTimer(mTimeInMillis,1000){
        override fun onTick(millisUntilFinished: Long) {
            mTimeInMillis= millisUntilFinished
            mTimeInMillis++
            updateCountDownText()
        }

"

увеличение переменной mTimeLeftInMillis ??? а как и где ?? Спасибо

1 Ответ

0 голосов
/ 14 ноября 2019
okay. instead of changing the mTimeInMillis, which i was not able to, i used 2 vars.to let the Countdowntimer count up:
internal var min = 0
    internal var sec = 0
then i changed the updateCountDownText to:
   private fun updateCountDownText(){
        if (sec == 59) {
            sec = 0
            min = min + 1
            val timeMinSec = String.format(Locale.getDefault(), "%02d:%02d", min, sec)
            tvTime.setText(timeMinSec)
        } else {
            sec = sec + 1
            val timeMinSec = String.format(Locale.getDefault(), "%02d:%02d", min, sec)
            tvTime.setText(timeMinSec)
        }
    }
and at last , i used the updateCountDownText in the startTimer function:
private fun startTimer() {
        mTimer = object : CountDownTimer(1000000000, 1000) {
            override fun onTick(millisUntilFinished: Long) {
                updateCountDownText()
            }
...