Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Alexandros04
Posts: 12
Registered: ‎02-22-2011
My Device: Bold 9780
Accepted Solution

java timer

I'm trying to make implement a timer into an app. I want a buton to trigger a timer whcih will stop when I click again on the buton and then will save the time between the clicks to us eit for further purposes.

But I can't find how to make a timer. Anyone an idea?

 

 

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: java timer

If you just want to know the time difference, then

System.currentMillis()

will give you this.

 

If not, can you explain what you are actually trying to do?  If you are struggling with creating a 'clock' that ticks, can you tell us what you have tried and why it has not worked.

Contributor
Alexandros04
Posts: 12
Registered: ‎02-22-2011
My Device: Bold 9780

Re: java timer

I think the time difference will work for me. I'll try it out as soon as I can and report back.
Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: java timer

OK.  I should have made it clear that you have to save the time on the first click, and subtract this from the time on the second click.  Result will be in milliseconds. 

 

Good luck

Contributor
Alexandros04
Posts: 12
Registered: ‎02-22-2011
My Device: Bold 9780

Re: java timer

Ok thank you for the extra info.
Contributor
Alexandros04
Posts: 12
Registered: ‎02-22-2011
My Device: Bold 9780

Re: java timer

[ Edited ]

ok so I got System.currentTimeMillis(), now I want the output to be written in an basicEditFIeld, how can I do that?

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: java timer

Assuming you just want to display seconds, then something simple like:

 

Assume you have previously defined and added to the screen this Field

BasicEditFielld timeElpasedField = new BasicEditField("Seconds: ", null, 25, BasicEditField.READONLY);

 

long elapsedTime = System.currentMillis() - previousTime;

timeElpasedField.setText(Long.toString(elapsedTime /1000));

Contributor
Alexandros04
Posts: 12
Registered: ‎02-22-2011
My Device: Bold 9780

Re: java timer

Wow thank you very much, I'll try it out as soon as I can
Contributor
Alexandros04
Posts: 12
Registered: ‎02-22-2011
My Device: Bold 9780

Re: java timer

Than you very very much, I tried the code and it works perfect! Exaclty as I want.