chronometer in android how to check whether chronometer is running or stop? if start then i want to stop it and if not running then start chronometer.
You can check this using boolean variable.when you start chronometer you set boolean variable true and when it stop you set boolean variable false.
boolean isChronometerRunning = false;
if (true) // condition on which you check whether it's start or stop
{
chronometer.start();
isChronometerRunning = true;
}
else
{
chronometer.stop();
isChronometerRunning = false;
}
You can extend
Chronomter
, like this:
import android.content.Context;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.widget.Chronometer;
public class MyChronometer extends Chronometer {
private boolean isRunning = false;
public MyChronometer(Context context) {
super(context);
}
public MyChronometer(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyChronometer(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void start() {
super.start();
isRunning = true;
}
@Override
public void stop() {
super.stop();
isRunning = false;
}
public boolean isRunning() {
return isRunning;
}
}
And then just call isRunning()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With