SoFunction
Updated on 2025-04-07

How to customize the Toast tool class ToastUtil prevent Toast from disappearing when multiple clicks

How to customize the Toast tool class ToastUtil prevent Toast from disappearing when multiple clicks

Updated: April 11, 2017 09:22:41 Submission: jingxian
Below, the editor will bring you a method to customize the Toast tool class ToastUtil to prevent Toast from disappearing after multiple clicks. The editor thinks it is quite good, so I will share it with you now and give you a reference. Let's take a look with the editor

Sometimes when we click a button, we will appear toast, but when we accidentally click multiple times, toast will appear repeatedly. At this time, the problem of accidentally clicking multiple times can be achieved through the ToastUtil class below.

public class ToastUtil {
 /* private Context context;
  public ToastUtil(Context context) {
  =context;
  }*/
  private static Toast toast;
  public static void showToast(Context context,int code,String content)
  {
    // When code=1, Toast displays for a long time, and when code=0, it is short.    if (toast==null)
    {
      if (code ==0)
      toast=(context,content,Toast.LENGTH_SHORT);
      if (code==1)
        toast=(context,content,Toast.LENGTH_LONG);
    }
    else
    {
      (content);
    }
    ();
  }
}

The above method to prevent Toast from disappearing when multiple clicks are all the content shared by the editor. I hope it can give you a reference and I hope you can support me more.

  • android
  • toast
  • Tools

Related Articles

  • Detailed explanation of Android performance optimization: Weak network optimization

    This article mainly introduces a detailed explanation of the weak network optimization example of Android performance optimization. Friends in need can refer to it for reference. I hope it can be helpful. I wish you more progress and get a promotion as soon as possible.
    2022-10-10
  • Android implements calling the camera to take photos and store photos

    This article mainly introduces how to use Android to call the camera to take pictures, and display the pictures after taking pictures into ImageView. The sample code in the article is explained in detail. If you are interested, you can try it.
    2022-01-01
  • Implementation of Android custom horizontal sliding menu

    This article mainly introduces the implementation of Android's custom horizontal sliding menu. The editor thinks it is quite good. I will share it with you now and give you a reference. Let's take a look with the editor
    2018-05-05
  • How to uninstall Android Studio cleanly

    This article mainly introduces how to uninstall Android Studio cleanly. The article focuses on the theme and has a certain reference value. Friends who need it can refer to it.
    2022-09-09
  • A comprehensive and detailed explanation of the basic usage of Android AOP

    This article mainly introduces the basic usage of Android AOP for you. Friends in need can refer to it for reference. I hope it can be helpful. I wish you more progress and get a promotion as soon as possible.
    2023-09-09
  • Network packaging example for beginners

    Hello everyone, this article mainly talks about the examples of network packaging for beginners. Interested students should take a look. If it is helpful to you, remember to bookmark it for the convenience of browsing next time.
    2021-12-12
  • Listview example introduction to change the font color of the selected row

    Select item, its font is set to #3197FF, and unselected, its font is #FFFFFF. Let me share with you how to change the font color of the selected line. Interested friends can refer to it.
    2013-06-06
  • Example of Android using ExpandableListView control to achieve novel directory effect

    This article mainly introduces examples of Android using ExpandableListView control to achieve the effect of novel directory, and can also achieve the secondary list display effect. Friends who need it can refer to it
    2014-07-07
  • Example of transition animation of Android 5.0

    This article mainly introduces an example of the transition animation of Activity in Android 5.0. It is very practical. Friends who need it can refer to it.
    2017-10-10
  • Android development search box SearchView usage example

    This article mainly introduces the usage of search box SearchView in Android development, and analyzes the basic functions, usage and related operation precautions of searchView in Android search box SearchView in combination with examples. Friends who need it can refer to it.
    2019-03-03

Latest Comments