zoukankan      html  css  js  c++  java
  • 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;
        }
       
    }
    
  • 相关阅读:
    剑指offer11-二进制中1的个数
    剑指offer10-矩形覆盖
    剑指offer08-跳台阶
    剑指offer07-斐波那契数列
    剑指offer04-重建二叉树
    剑指offer62-二叉搜索树的第k个结点
    kimball维度建模(5)-拉链表原理、设计以及在Hive中的实现
    kimball维度建模(4)-统一数仓层DW与事实表设计
    C-宏定义
    lua-设计与实现-8环境与模块
  • 原文地址:https://www.cnblogs.com/loaderman/p/7081591.html
Copyright © 2011-2022 走看看