我上课延长了倒数计时器

我想在onfinish()中祝酒,每次在从其实例化的任何对象中从任何其他类调用onfinish()函数时,该函数都会显示

我怎样才能做到这一点 ?

package com.fawzyx.exams_countdowntimer;

import android.os.CountDownTimer;
import android.text.InputFilter.LengthFilter;
import android.widget.Toast;

public class CountDown extends CountDownTimer {

    public CountDown(long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
/*
millisInFuture : The number of millis in the future from the call to start() until the countdown is done and onFinish() is called.
countDownInterval : The interval along the way to receive onTick(long) callbacks.

*/


    }

    @Override
    public void onFinish() {
        // TODO Auto-generated method stub

        Toast.makeText(getApplicationContext() ,"Done", Toast.LENGTH_LONG);

    }

    @Override
    public void onTick(long millisUntilFinished) {
        // TODO Auto-generated method stub

    }

}

最佳答案

您需要将上下文传递给CounteDown类

new CountDown(MyActivityName.this,otherparams);


现在使用传递的上下文显示吐司

Context context;
public CountDown(Context context,long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
this.context = context;
}


然后在onFinish()

Toast.makeText(context," Message", Toast.LENGTH_SHORT).show();

07-24 09:47
查看更多