Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Taebin You
Taebin You
4,786 Points

Android Countdown Timer

I am trying to use countdown timer and having problem assigning the value

in main activity I have

public long time;
public final long interval = 1 * 1000;

declared (was private long, didn't work, public also not working) and in the CountDownTimer class

public class MyCountDownTimer extends CountDownTimer {
        public MyCountDownTimer(long time, long interval) {
            super(time, interval);
        }

        @Override
        public void onFinish() {
            text.setText("Time's up!");
        }
        @Override
        public void onTick(long millisUntilFinished) {
            text.setText("" + millisUntilFinished / 1000);
        }
    }

I have this. But time, interval in timer class does not match the time, interval in main activity. I've tired to use getter as well, but didn't have luck. Why the code above does not work?

Please Help!

[Code blocks edited by moderator - srh]

1 Answer

Seth Kroger
Seth Kroger
56,413 Points

What about the code where you create a new MyCountDownTimer? are you passing the correct values to the constructor?

Taebin You
Taebin You
4,786 Points

I just made it global..Thx for answering tho!