android - quiz program Timer issue -
i'm creating 1 quiz application android in using timer.based on timer questions move next. there 20 questions. giving 6 seconds of time each question. should answer within 6 seconds otherwise question move next question. if answer in 4 seconds means remaining 2 seconds added next question. next question have 8 seconds of time. have add remaining seconds next question till end. used below code has start , stop timer.
private runnable updatetimerthread = new runnable() { public void run() { timeinmilliseconds = systemclock.uptimemillis() - starttime; updatedtime = timeswapbuff + timeinmilliseconds; int secs = (int) (updatedtime / 1000); int mins = secs / 60; secs = secs % 60; mtimertext.settext("" + mins + ":" + string.format("%02d", secs)); customhandler.postdelayed(this, 0); } }; public void playclock() { starttime = systemclock.uptimemillis(); customhandler.postdelayed(updatetimerthread, 0); if (systemclock.elapsedrealtime()==6) { getquestion(); //here call question } } public void resumeclock() { timeswapbuff += timeinmilliseconds; customhandler.removecallbacks(updatetimerthread); }
you have use countdowntimer
try below method starttimmer(6) when timmer complate there method finishquiztime();
called(set next question detail in method).
when user select answer call finishquiztime();
& stop countdowntimer
using mcountdown.cancel();
/** * timer quiz question * */ public void starttimmer(int currentquesec) { log.e("start timmer ", "--->" + currentquesec); mcountdown = new countdowntimer(currentquesec, 1000) { @override public void onfinish() { /** * stop timmer * */ finishquiztime(); log.e("time finish", "time finish"); } @override public void ontick(long millisuntilfinished) { quelasttime = millisuntilfinished / 1000; } }.start(); }
Comments
Post a Comment