Android reset



  • There's a code like this:

    mButton = (Button) rootView.findViewById(R.id.btn1);
    mTimer = (TextView) rootView.findViewById(R.id.textView3);
    mButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new CountDownTimer(130000, 1000) {
                @Override
                public void onTick(long millisUntilFinished) {
                    mTimer.setText("Осталось" + millisUntilFinished / 1000);
                }
    
            @Override
            public void onFinish() {
                mTimer.setText("");
            }
        }.start();
    }
    

    });

    How do you create a button that could be: stop or reset the timer?



  • mButton = (Button) rootView.findViewById(R.id.btn1);
    mTimer = (TextView) rootView.findViewById(R.id.textView3);
    
    final CountDownTimer timer = new CountDownTimer(130000, 1000) {
        @Override
        public void onTick(long millisUntilFinished) {
            mTimer.setText("Осталось" + millisUntilFinished / 1000);
        }
    
        @Override
        public void onFinish() {
            mTimer.setText("");
        }
    };
    
    mButton.setOnClickListener(timer);
    timer.start();
    

    Now determine where you will stop him and do it.

    timer.cancel();
    



Suggested Topics