Ravi Bhardwaj
Ravi Bhardwaj

Reputation: 148

Timer - to count Time

I am making a quiz application, in which I want to show the time used by the user while playing a session of game. It should be in format HH:MM:SS starting from 00:00:00 till he selects the answer. Timer should be updating every second while user is playing each second. Also, I want to pause the timer while next question is loading. I am not able to understand how to do this. Right now I am able to fetch current time by this code.

Calendar c = Calendar.getInstance();
                SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
                final String startTime = timeformat.format(c.getTime());
                Play.timer_box.setText(""+startTime);

It just display whatever the current time is in the box in right format. But not able to understand how to achieve what i want to

Upvotes: 1

Views: 203

Answers (1)

Tejshree
Tejshree

Reputation: 106

You cant just show the time using calendar,you have to write the logic

  1. Start counter when activity/fragment is resumed till user selects answer
  2. Stop it once user selects the ans,ans start it again once next question (activity/fragment is loaded)
  3. Convert counter to the time format you want to display,you will need a logic for the same

Upvotes: 1

Related Questions