How to use Chronometer in Android?

Discussion in 'Java' started by Ashish Bisht, Aug 4, 2016.

  1. Ashish Bisht

    Ashish Bisht New Member

    Joined:
    Aug 4, 2016
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    Gender:
    Male
    Hi, i am looking for some example code that help me to create Chronometer in Android that can act as a timer for Android Applications. Hoping for valuable suggestions.
     
  2. meenal deshpande

    meenal deshpande New Member

    Joined:
    Oct 11, 2018
    Messages:
    20
    Likes Received:
    2
    Trophy Points:
    3
    Gender:
    Female
    hronometer can be started by calling start method. Before chronometer is started, you need to set starting point of time from that you want chronometer to start the count, by using setBase method and passing starting point of time. By default, meaning if you don’t set base, it starts counting from 0 because Chronometer’s default base time is time at which start method is called.

    Even if you set base to SystemClock.elapsedRealtime(), counting will start from 0, this is how Chronometer gets its default base.

    To stop chronometer, you need to call stop method on it. Start and stop methods don’t change the base, they just start and stop showing count in the text view. That means Chronometer never stops counting once it is started. But you can rest base by calling setBase with a new starting point.

    Chronometer timer by default displays time in "MM:SS" or "H:MM:SS, you can change it by using setFormat method.
     
  3. sayalipatil

    sayalipatil New Member

    Joined:
    Dec 18, 2018
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    Gender:
    Female
    Home Page:
    https://crbtech.in/online-java-training-course
    Methods Of Chronometer In Android:

    1. start(): start function of chronometer is used to start the counting up.

    2. stop(): stop function of chronometer is used to stop the counting up.

    3. setFormat(String format): set format function of chronometer is used to set the format string used to display. In other words we can say it is used to display text, numbers etc along-with chronometer.

    4. getformat(): This function of chronometer is used for getting the current format string. This methods returns a string type value.

    5. setOnChronometerTickListener(Chronometer.OnChronometerTickListener listener): This is a listener event which is automatically called when the chronometer changes.

    6. setBase(long base): set base function of chronometer is used to set the time that count up time is in reference to. You can give it a start time in the elapsedRealtime() timebase, and it counts up from that, or if you don’t give it a base time, it will use the time at which you call start().

    7. getBase(): get base function is used to get the base time from a chronometer. This method returns a base time as set through the setBase() function. This method return long value.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice