12:02 PM
0
1/. Create CountDownHandler class
private final Runnable mCountDown = new Runnable() {
        public void run() {
            if (mCurrentCount > 0) {
                mCurrentCount--;
            } else {
                // Your code here
        }
    };
Create method to start and stop countDown
/**
     * Starts the count down animation.
     */
    public void start() {
        mHandler.removeCallbacks(mCountDown);

        mTextView.setText(mStartCount + "");
        mTextView.setVisibility(View.VISIBLE);

        mCurrentCount = mStartCount;

        mHandler.post(mCountDown);
        for (int i = 1; i <= mStartCount; i++) {
            mHandler.postDelayed(mCountDown, i * 1000);
        }
    }

    /**
     * Cancels the count down animation.
     */
    public final void cancel() {
        mHandler.removeCallbacks(mCountDown);
    }
/**
     * Sets a new starting count number for the count down animation.
     *
     * @param startCount
     *            The starting count number
     */
    public void setStartCount(int startCount) {
        this.mStartCount = startCount;
    }

    /**
     * Returns the starting count number for the count down animation.
     */
    public int getStartCount() {
        return mStartCount;
    }
 

0 comments:

Post a Comment