java - Count up timer on Android? -
i've been looking way create timer counts in format of mm:ss:ss , cannot life of me find way of doing it. had timer running through handler , runnable timing off , took around 2.5 seconds "second". i'll need timer able countdown too!
can give me resources or code snippets research on big part of app i'm coding.
here's bit of code using
private handler handler = new handler(); private runnable runnable = new runnable() { @override public void run() { /* need */ testmethod(); /* , here comes "trick" */ handler.postdelayed(this, 10); } }; public void testmethod() { // log.d("testing", "test"); final textview timelabel = (textview)findviewbyid(r.id.timestring); count++; seconds = (int)(count / 100); final string str = ""+count; runonuithread(new runnable() { public void run() { timelabel.settext("" + seconds); // log.d("time", "" + count); } }); }
ta!
make small custom class extending countdowntimer class , add integer or long type , increment it, since each tick 1 second (integer) in case
public class timecounter extends countdowntimer { // seconds counter int countuptimer; public timecounter(long millisinfuture, long countdowninterval) { super(millisinfuture, countdowninterval); countuptimer=0; } @override public void ontick(long l) { //since each tick interval 1 second // add 1 each time mytextview.settext("seconds:"+countuptimer); countuptimer = countuptimer+1; } @override public void onfinish() { //reset counter 0 if want countuptimer=0; } } timecounter timer = new timecounter(whentostopinseconds*1000, 1000);
this should started, in case use long instead integer countuptimer = countuptimer+1000
countuptimer type , time parsing suits you
Comments
Post a Comment