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

后端 未结 11 1388
粉色の甜心
粉色の甜心 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 18:14

    You can use one shoot technique. Oke let's start defining:

    private Toast mToast;
    private showOnce=false;
    

    Later when you wanna show toast once:

    if(showOnce==false){
      mToast=Toast.makeText(this, "Once!", Toast.LENGTH_LONG);
      mToast.show();
      showOnce=true;
    }
    

提交回复
热议问题