How to prevent Multiple Toast Overlaps

后端 未结 8 1108
难免孤独
难免孤独 2020-11-29 07:26

I\'ve been using a common \"myToast\" which I use \"myToast.cancel() prior to issuing a new toast. For Android v2.3 and older, this works great. When a new toas

8条回答
  •  一个人的身影
    2020-11-29 07:52

    Create an Toast Object:

    Toast toastobject=null;
    

    Now use the below code to display the toast. This will work find for me

        int index = clickCounter-1;
    
    
        if(toastobject!= null)
                {
                    toastobject.cancel();
                }
                toastobject = Toast.makeText(this,"Toast Text" , Toast.LENGTH_SHORT);
                listItems.remove(index);
                toastobject.show();
    

提交回复
热议问题