java - how to display the end and start time android countdowntimer -
when run code below can not display start , end time 00:00:00 every time timer start, in future want let user define how many countdown timer need , time each 1 repeat on them assist display vital , if can improve code next step appreciate that.
thank assist,
repetertimer = new countdowntimer(3000, 1000) { @override public void ontick(long millisuntilfinished) { isrunning = true; meditiongong.setlooping(false); long millis = millisuntilfinished; string hms = string.format("%02d:%02d:%02d", timeunit.milliseconds.tohours(millis), timeunit.milliseconds.tominutes(millis) - timeunit.hours.tominutes(timeunit.milliseconds.tohours(millis)), timeunit.milliseconds.toseconds(millis) - timeunit.minutes.toseconds(timeunit.milliseconds.tominutes(millis))); textviewtimer.settext(hms); } @override public void onfinish() { textviewtimer.settext("00:00:00"); isrunning = false; meditiongong.start(); if (repeater) { numrepeat ++ ; numofrepeat.settext("" + numrepeat); repetertimer.start(); } else { meditiongong.setlooping(true); } } }; }
first need textview values timer displayed. have example of countdown timer value display:
private textview remainingtimedisplay; private int timerprogressstatus; remainingtimedisplay = (textview) findviewbyid(r.id.remainingtimedisplay); private void setquiztimer(int time) { final int actualtime = time*1000; countdowntimer gamecountdowntimer = new countdowntimer(actualtime, 1000) { int totaltime = actualtime; @override public void ontick(long millisuntilfinished) { /*display time left in textview*/ long millis =string.format("%02d:%02d:%02d", timeunit.milliseconds.tohours(millis), timeunit.milliseconds.tominutes(millis) - timeunit.hours.tominutes(timeunit.milliseconds.tohours(millis)), timeunit.milliseconds.toseconds(millis) - timeunit.minutes.toseconds(timeunit.milliseconds.tominutes(millis))); remainingtimedisplay.settext(hms); /*progress bar display values*/ timerprogressstatus = (int)(( totaltime - millisuntilfinished ) /(double)totaltime * 100); timerprogressbar.setprogress(timerprogressstatus); } @override public void onfinish() { toast.maketext(questionactivity.this,"countdown ended",toast.length_short).show(); } }.start(); }
when want use method need call number of secounds. ex: 10 secounds setquiztimer(10); output 09:59, hope helps.
Comments
Post a Comment