Created
September 19, 2018 17:15
-
-
Save Alynva/565828f91ba1c28a2c58f33941cdba9b to your computer and use it in GitHub Desktop.
setInterval in Kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val handler = Handler(Looper.getMainLooper()) | |
val runnable = object : Runnable { | |
override fun run() { | |
if (countProgress.progress > 0) { | |
val new_time = countProgress.progress.toInt() - 1 | |
timeLabel.text = "$new_time segundos" | |
countProgress.progress = new_time | |
} | |
handler.postDelayed(this, 1000) | |
} | |
} | |
playCount.setOnClickListener() { | |
handler.postDelayed(runnable, 1000) | |
} | |
pauseCount.setOnClickListener() { | |
handler.removeCallbacks(runnable) | |
} |
Hi. Sure, what you need?
I wanted to know what libraries you use for your code because it doesn't
run very well For me I think maybe I'm confused by the variables you use
…On Thu, Jul 4, 2019, 18:05 Alisson Nunes ***@***.***> wrote:
Hi. Sure, what you need?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://gist.github.com/565828f91ba1c28a2c58f33941cdba9b?email_source=notifications&email_token=AITBZJNJD52GNSWUDMLUG6DP5Z65FA5CNFSM4H6BGJPKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFUZWG#gistcomment-2962275>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AITBZJOAWV3CLUAPSSUK53LP5Z65FANCNFSM4H6BGJPA>
.
timeLabel
is just an TexView and countProgress
is an ProgressBar, but it can be replaced by any other counter variable. For the setInterval
, the if
block doesn't matter, just replace it with the code that you want to be runned every N milliseconds (in this case, 1000)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, I need a litlle help this code. Please could you answer me.