timer-like issue

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

timer-like issue

Postby Lenea » Wed Dec 30, 2009 3:36 pm

hey all, i'm developing this app which keeps scores for various reasons, one issue i'm having is the following :
i have a number on the screen and the button "+" and "-". if i hit + the number gets +1, if i hit - the number gets -1, the issue is, i want the number to move onto a new line when + or - is touched, but not each time, ONLY IF the number hasn't been changed for like, 5 seconds or so. any way to do that?

L.E : for example :
if the number on the screen is 5
and i hit +, +, + .....(pause) .. +
on the screen there should be :

Posts: 6
Joined: Mon Dec 28, 2009 12:49 am


Postby DMacATTACK » Thu Dec 31, 2009 6:56 pm

Kind of a confusing description you have there, but I think I get it.
Without seeing your code I can only suggest pseudo-code.

Timing is a tricky thing, there are 2 basic ways to deal with the time, each with their own pros and cons.

1) Using a timer

Well to enable the line change after a 5 second delay you can have a "flag" set or reset.
Set up a continuous timer that runs in a thread of its own, and when it reaches the 5 second time limit a flag gets set. Whenever the score is changed the flag is checked and reset.

2) Using the system clock

You can convert the system clock to seconds, and check that everytime the score is updated, and if the difference is >5s then use a new line.
User avatar
Experienced Developer
Experienced Developer
Posts: 58
Joined: Thu Dec 31, 2009 6:31 pm
Location: Canada


Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 6 guests