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

  • SEARCH
  • Home
  • 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 6872811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:58:36+00:00 2026-05-27T03:58:36+00:00

I’m trying to make a countdown timer starting at 10 minutes, similair to a

  • 0

I’m trying to make a countdown timer starting at 10 minutes, similair to a basketball scoreboard: 10:00 to 00:00. How would I do that? This is my code:

private TextView Timer;  
Handler handler = new Handler();  
private int length = 120000;  
private int decision = 0;  
MyCount counter;  

public String formatTime(long millis) {  
    String output = "00:00";  
    long seconds = millis / 1000;  
    long minutes = seconds / 60;  

    seconds = seconds % 60;  
    minutes = minutes % 60;  

    String sec = String.valueOf(seconds);  
    String min = String.valueOf(minutes);  

    if (seconds < 10)  
        sec = "0" + seconds;  
    if (minutes < 10)  
        min= "0" + minutes;  

    output = min + " : " + sec;  
    return output;
}//formatTime  

@Override  
public void onCreate(Bundle cute) {  
    super.onCreate(cute);  
    counter = new MyCount(length, 1000);  
    updateTime();  
    handler.removeCallbacks(updateTimeTask);  
    handler.postDelayed(updateTimeTask, 1000);   
}//end of cuteness  

private Runnable updateTimeTask = new Runnable() {  
    public void run() {  
        updateTime();  
        handler.postDelayed(this, 1000);  
    }  
};  

private void updateTime() {  
    switch (decision) {  
        case 0:  
            startTime = 0L;  
            counter.start();  
            decision=1;  
            break;  
        case 1:  
            counter.onPause();  
            decision=0;  
            break;  
    }  
}//updateTime  

class MyCount extends CountDownTimer {  
    public MyCount(long millisInFuture, long countDownInterval) {  
        super(millisInFuture, countDownInterval);  
    }//MyCount  

    public void onPause() {  
        //do stuff later  
        onPause();  
    }//finish  

    public void onTick(long millisUntilFinished) {             
        Timer.setText("" + formatTime(millisUntilFinished));           
    }//on tick  

    @Override  
    public void onFinish() {  
        onStop();  

    }//finish  
}//class MyCount  

Any help would be appreciated. thanks!

  • 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-27T03:58:37+00:00Added an answer on May 27, 2026 at 3:58 am

    This does not have to be too hard. You’ve already created your functionality for writing your time in letters, now you need to count down. Starting a timer is easy, just do this in your start button event handler (or whatever you choose to use) (modified example from the android developer reference:

    // New timer for 10 minutes, starts after initialization
    new MyCount(600000, 1000) 
    {
        // Updates the text on your "scoreboard" every second
        public void onTick(long millisUntilFinished) 
        {
            Timer.setText("Time remaining: " + formatTime(millisUntilFinished));
        }
    
        public void onFinish() 
        {
            mTextField.setText("done!");
        }
    }.start();
    

    And that’s all you need! You can skip your UpdateTime function and your updateTimeTask. Just replace all this on your onCreate method

    counter = new MyCount(length, 1000);  
    updateTime();  
    handler.removeCallbacks(updateTimeTask);  
    handler.postDelayed(updateTimeTask, 1000); 
    

    With my code. Or modify it as you please!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string

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.