Can I cancel previous Toast when I want to show an other Toast?

后端 未结 11 1381
粉色の甜心
粉色の甜心 2020-12-05 17:18

In my app, I construct a calendar widget for my activity, when I scroll it to previous or next month, I let it make a toast and show it.

The question is, the toast n

11条回答
  •  南方客
    南方客 (楼主)
    2020-12-05 17:54

    You just need to declare a "Toast" var like this:

    Toast toastMessage;
    

    Then in your function, do it like this:

    if (toastMessage!= null) {
        toastMessage.cancel();
    }
    toastMessage= Toast.makeText(context, "The message you want to display", duration);
    toastMessage.show();
    

提交回复
热议问题