Format the Chronometer

Asked

Viewed 62 times

0

In my application I inserted a Chronometer that simulates a playing time... but when I click stop and then continue it shows me in format (00:00:00:00) and wanted to show me again at (00:00)

Note: show me in milliseconds

code:

private Chronometer reloginho;
long tempoPausado = 0;

     imgButton_play.setEnabled(true);
            imgButton_pause.setEnabled(false);
            imgButton_1.setEnabled(false);
            imgButton_2.setEnabled(false);


            imgButton_play.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    imgButton_play.setEnabled(false);
                    imgButton_pause.setEnabled(true);
                    imgButton_1.setEnabled(true);
                    imgButton_2.setEnabled(true);

                    reloginho.setBase(SystemClock.elapsedRealtime());
                    reloginho.start();
                    reloginho.setBase(SystemClock.elapsedRealtime() + tempoPausado);
                }
            });

            imgButton_pause.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    imgButton_play.setEnabled(true);
                    imgButton_pause.setEnabled(false);
                    imgButton_1.setEnabled(false);
                    imgButton_2.setEnabled(false);

                    tempoPausado = reloginho.getBase();
                    SystemClock.elapsedRealtime();
                    reloginho.stop();
                }
            });

Thank you...

1 answer

0

As Voce said to already have the formatted text being displayed, it should be in some textview or something like that, am I right? so just convert this hour into a string, try something like this:

    //...
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
    Date hora = reloginho.getInstance().getTime(); // Ou qualquer outra forma que tem
    String horaFormatada = sdf.format(hora);
    //...
    relogioTextView.setText(horaFormatada);
    //...

hopefully that’s what!!

Health and Peace!

  • Good morning friend... it would not be a Textview will own the Chronometer property... even if I paste this code it presents me the error in getInstance() and the watchTextView switched to watchmaking.setText(...)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.