Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4596202
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:04:53+00:00 2026-05-21T23:04:53+00:00

in my app i have placed a stop watch with two buttons. The stop

  • 0

in my app i have placed a stop watch with two buttons. The stop watch works in a proper way. But the problem is at start the timer looks as 0:0:0, when it starts counting the single digits are been changed over to double digits as 0:12:53.

this affects and disturbs the other layers too. At the start itself i want it to be displayed as 00:00:00 by default, so that i cant make changes in the layout.

but i don’t know where to give the value for this. Following is my code

  b1.setOnClickListener(new View.OnClickListener() 
        {
            public void onClick(View view) 
            {
                if(b1.getText().toString().equals("Start"))
                {
                        if(currentThread.getState()==Thread.State.NEW)
                        {
                            currentThread.start();
                            shouldRun = true;
                            b1.setText("Stop");
                        }
                        else
                        {
                          shouldRun = false;
                          b1.setText("Stop");
                        }
                }
                else if(b1.getText().toString().equals("Stop"))
                {
                    time=0;
                    time1=0;
                    time2=0;
                }
            }
        });     
        b2.setOnClickListener(new View.OnClickListener() 
        {
            public void onClick(View view) 
            {
                if(b2.getText().toString().equals("Pause"))
                {
                    shouldRun = false;
                    b2.setText("Resume");
                }
                else if(b2.getText().toString().equals("Resume"))
                {
                    shouldRun = true;
                    b2.setText("Pause");
                }
            }
        });               
    }
    @Override
    public void run()
    {
        try 
        {
         while(true)
         {  
            while(shouldRun)
            {
                Thread.sleep(1000);
                Log.e("run", "run");
                threadHandler.sendEmptyMessage(0);
            }
         }   
        } 
        catch (InterruptedException e) {}
    }


    private Handler threadHandler = new Handler() 
    {
        public void handleMessage(android.os.Message msg) 
        {
            sec=time2++;
            if(sec == 59)
            {
                time2=0;
                sec = time2++;
                min=time1++;
            }
            if(min == 59)
            {
                time1=0;
                min = time1++;
                hr=time3++;
            }             
            stopWatch.setText(""+hr+":"+min+":"+sec);
        }
    };

}

how to do this please help me…………

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T23:04:54+00:00Added an answer on May 21, 2026 at 11:04 pm

    This should do the work:

    String time = String.format("%02d:%02d:%02d", hr, min, sec);
    stopWatch.setText(time);
    

    Or the one-line-version:

    stopWatch.setText(String.format("%02d:%02d:%02d", hr, min, sec));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have user control in my MVC2 app placed in the Content folder (it's
my app have action bar on top of windows. Where are some buttons. Buttons
I have an empty app.config file, but I still get NHibernate debug logs NHibernate:
I have an app where I am creating two subviews of the main window,
How to access App_Data folder in WCF service? I have placed a xslt file
Why is that Web Service files (.asmx) have their code-behind placed in app_code folder
I have a place in my Django app where I need to construct a
I'm working on a class-based php web app. I have some places where objects
I have this need to place my app in the share/send context menu so
I have read in many places that network connection in a j2me app should

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.