How to Show Countdown timer in HH:MM:SS (Hours : Minutes : Seconds)

mcode :

How to make the countdown 'HH: mm: ss' from the XMl android that I made, when within 24 hours there is no interaction then cannot do the transaction again or cannot be accessed again

This code is design UI for countdown timer.

Countdown Timer

<androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/constrainlayout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="18dp"
        android:layout_marginEnd="20dp"
        android:layout_marginRight="20dp"
        android:background="@drawable/bg_color_orange"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/app_bar">

        <TextView
            android:id="@+id/textView_Title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="18dp"
            android:text="Please make a payment Immediatelly"
            android:textColor="@android:color/black"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/constrainlayout" />

        <TextView
            android:id="@+id/textView_TimeCountDown"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="18dp"
            android:text="13 Hour: 59 Minute: 21 Second"
            android:textColor="@android:color/black"
            android:textSize="22sp"
            app:layout_constraintEnd_toEndOf="@+id/textView_Title"
            app:layout_constraintStart_toStartOf="@+id/textView_Title"
            app:layout_constraintTop_toBottomOf="@+id/textView_Title" />

        <TextView
            android:id="@+id/textView_Day"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="18dp"
            android:layout_marginBottom="18dp"
            android:text="(Before Thursday, 16 January 2020, 13:33 WIB)"
            android:textColor="@android:color/black"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="@+id/textView_Title"
            app:layout_constraintStart_toStartOf="@+id/textView_Title"
            app:layout_constraintTop_toBottomOf="@id/textView_TimeCountDown" />

    </androidx.constraintlayout.widget.ConstraintLayout>

That code will get display like this

countdown timer

Nensi Kasundra :

It's help for you

 private void startTimer(int noOfMinutes) {
        CountDownTimer  countDownTimer = new CountDownTimer(noOfMinutes, 1000) {
        public void onTick(long millisUntilFinished) {
            long millis = millisUntilFinished;
            //Convert milliseconds into hour,minute and seconds
            String hms = String.format("%02d:%02d:%02d", 
            TimeUnit.MILLISECONDS.toHours(millis), 
            TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)), TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));
            countdownTimerText.setText(hms);//set text
        }
        public void onFinish() {
            countdownTimerText.setText("TIME'S UP!!"); //On finish change timer text
        }
    }.start();

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=27077&siteId=1