wpc
2018-11-27 c52fb0e4d9168e75390b3cf3536d66c06c50d605
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.lcjian.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 Handler mHandler = new Handler();
    private static Runnable r = new Runnable() {
        public void run() {
            mToast.cancel();
        }
    };
 
    public static void showToast(final Context mContext, final String text) {
 
        mHandler.removeCallbacks(r);
//        mContext.runOnUiThread(new Runnable() {
//
//            @Override
//            public void run() {
//                //更新UI
//                if (mToast != null) {
//                    mToast.setText(text);
//                } else {
//                    mToast = Toast.makeText(mContext, text, Toast.LENGTH_LONG);
//                }
//            }
//
//        });
 
        if (mContext == null)
            return;
 
        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));
    }
 
}