admin
2021-07-06 abce02c7a61820f5d580f87364d542e817be429c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.wpc.library.util;
 
import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.widget.Toast;
 
public class SingleToast {
    private static Toast mToast;
    private static Context mContext;
    private static Handler mHandler = new Handler();
    private static Runnable r = new Runnable() {
        public void run() {
            if (mContext != null)
                mToast.cancel();
        }
    };
 
    public static void showToast(Context context, final String text) {
        mContext = context;
        mHandler.removeCallbacks(r);
 
        if (mToast != null)
            mToast.setText(text);
        else
            mToast = Toast.makeText(mContext, text, Toast.LENGTH_LONG);
        mHandler.postDelayed(r, 2000);
 
        mToast.show();
    }
 
    public static void showToast(Activity mContext, int resId, int duration) {
        showToast(mContext, mContext.getResources().getString(resId));
    }
 
}