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.
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.
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.