I'm trying to create a chronometer in android, using android.widget.Chronometer, that displays only hours and minutes (hh:mm), but untill now I didn't find a way to make it. I don't even know if this is possible with this widget.
Is this possible? If this is possible can you please show me how to do it?
Try this
Chronometer chronometer = (Chronometer) findViewById(R.id.chronometer);
chronometer.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener() {
public void onChronometerTick(Chronometer cArg) {
long time = SystemClock.elapsedRealtime() - cArg.getBase();
int h = (int) (time / 3600000);
int m = (int) (time - h * 3600000) / 60000;
cArg.setText(String.format("%02d:%02d", h, m));
}
});
chronometer.start();
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