dfg
dfg

Reputation: 27

How can i use countDown timer in android

I want use countDown timer in my application and i should create such as this : Click too see image

How can i create countDownTimer such as above design?

Upvotes: -4

Views: 8314

Answers (3)

Meysam Keshvari
Meysam Keshvari

Reputation: 1201

private void downTimer(){
    new CountDownTimer(120*1000,1000) {
        @Override
        public void onTick(long millisUntilFinished) {
            long second = (millisUntilFinished / 1000) % 60;
            long minutes = (millisUntilFinished/(1000*60)) % 60;
            textViewCountDownTimer.setText(minutes + ":" + second);
        }

        @Override
        public void onFinish() {
            textViewCountDownTimer.setText("Finish");
        }
    }.start();
}

Upvotes: 2

Tsur Yohananov
Tsur Yohananov

Reputation: 53

Maybe this can help you :

https://github.com/tsuryo/Android-Countdown-Timer

    <com.tsuryo.androidcountdown.Counter
    android:id="@+id/counte1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:max_time_unit="DAY"
    app:text_color="#2196F3"
    app:text_size="36dp"
    app:textual_description="true"
    app:counter_font="DIGITAL_BOLD" />

and Java:

mCounter = findViewById(R.id.counter);
mCounter.setDate("2019-07-19T18:33:00"); //countdown starts

Upvotes: 1

Rishabh Sharma
Rishabh Sharma

Reputation: 268

Example of showing a 30 second countdown in a text field:

new CountDownTimer(30000, 1000) {

    public void onTick(long millisUntilFinished) {
         mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
    }

    public void onFinish() {
         mTextField.setText("done!");
    }

}.start();

Visit https://developer.android.com/reference/android/os/CountDownTimer.html

Upvotes: 1

Related Questions