• ToastUtils


    import android.content.Context;
    import android.widget.Toast;
    
    public class ToastUtil {
        
        private static String oldMsg;
        private static long   time;
        private static int resOldMsg;
        public static void showToast(Context context, String msg, int duration ) {
            if (!msg.equals(oldMsg)) { // 当显示的内容不一样时,即断定为不是同一个Toast
                Toast.makeText(context, msg, duration).show();
                time = System.currentTimeMillis();
            } else {
                // 显示内容一样时,只有间隔时间大于2秒时才显示
                if (System.currentTimeMillis() - time > 2000) {
                    Toast.makeText(context, msg, duration).show();
                    time = System.currentTimeMillis();
                }
            }
            oldMsg = msg;
        }
        
        public static void showToast(Context context, String msg) {
            if (!msg.equals(oldMsg)) { // 当显示的内容不一样时,即断定为不是同一个Toast
                Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
                time = System.currentTimeMillis();
            } else {
                // 显示内容一样时,只有间隔时间大于2秒时才显示
                if (System.currentTimeMillis() - time > 2000) {
                    Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
                    time = System.currentTimeMillis();
                }
            }
            oldMsg = msg;
        }
        
        public static void showToast(Context context, int StringRes,int  duration) {
            if (StringRes!=resOldMsg) { // 当显示的内容不一样时,即断定为不是同一个Toast
                Toast.makeText(context, StringRes, duration).show();
                time = System.currentTimeMillis();
            } else {
                // 显示内容一样时,只有间隔时间大于2秒时才显示
                if (System.currentTimeMillis() - time > 2000) {
                    Toast.makeText(context, StringRes, duration).show();
                    time = System.currentTimeMillis();
                }
            }
            resOldMsg = StringRes;
        }
        
        public static void showToast(Context context, int StringRes) {
            if (StringRes!=resOldMsg) { // 当显示的内容不一样时,即断定为不是同一个Toast
                Toast.makeText(context, StringRes, Toast.LENGTH_SHORT).show();
                time = System.currentTimeMillis();
            } else {
                // 显示内容一样时,只有间隔时间大于2秒时才显示
                if (System.currentTimeMillis() - time > 2000) {
                    Toast.makeText(context, StringRes, Toast.LENGTH_SHORT).show();
                    time = System.currentTimeMillis();
                }
            }
            resOldMsg = StringRes;
        }
       
    }
    
  • 相关阅读:
    javaScript系列 [06]-javaScript和this
    javaScript系列 [05]-javaScript和JSON
    javaScript系列 [04]-javaScript的原型链
    javaScript系列 [03]-javaScript原型对象
    javaScript系列 [02]-javaScript对象探析
    javaScript系列 [01]-javaScript函数基础
    jQuery系列 第八章 jQuery框架Ajax模块
    jQuery系列 第七章 jQuery框架DOM操作
    jQuery系列 第六章 jQuery框架事件处理
    jQuery系列 第五章 jQuery框架动画特效
  • 原文地址:https://www.cnblogs.com/loaderman/p/7081591.html
Copyright © 2020-2023  润新知