views:

51

answers:

2

I am writing a app for which i need to display the Time elapsed when user presses a button in UI screen . So please guide me in writing the code in Android. I need to display the time in seconds, mins and hours.

Thanks in anticipation. Darshan

A: 

Here is a great example http://developer.android.com/resources/articles/timed-ui-updates.html

schwiz
A: 

You can get the current system time in milliseconds by calling System.currentTimeMillis(). You can store this in an variable on Activity start and then calculate the difference between the current time and the stored time in the onClick method of the button.

example:

class ExampleApp exnteds Activity {
    private long startTime;
    public void onCreate(Bundle sis) {
        startTime = System.currentTimeMillis();
        ...

    public void onMyButtonClick(View v) {
        long timeGoneMillis = System.currentTimeMillis() - startTime;
        long timeGoneSecs = timeGoneMillis / 1000;
        ...
Mannaz
Thanks guys for the heads up ! i also found solution for similar problem, so wanted share the URL : http://stackoverflow.com/questions/2536882?tab=newest#tab-top
ReachmeDroid