Untitled

mail@pastecode.io avatar
unknown
plain_text
9 days ago
852 B
3
Indexable
Never
 public void showToast() {
        // Set the toast and duration
        int toastDurationInMilliSeconds = 5000;
        mToastToShow = Toast.makeText(this, "Hello world, I am a toast.", Toast.LENGTH_LONG);

        // Set the countdown to display the toast
        CountDownTimer toastCountDown;
        toastCountDown = new CountDownTimer(toastDurationInMilliSeconds, 1000 /*Tick duration*/) {
            public void onTick(long millisUntilFinished) {
                String text= String.valueOf(millisUntilFinished/1000);
                tv1.setText(text);
                mToastToShow.show();
            }
            public void onFinish() {
                mToastToShow.cancel();
            }
        };

        // Show the toast and starts the countdown
        mToastToShow.show();
        toastCountDown.start();
    }
Leave a Comment