文章出處

在開發的時候我們會遇到點擊顯示第二個Toast的時候,當前Toast還沒有顯示完,導致第二個Toast不能立馬顯示,下面來解決這個問題:

用下面的工具類就行了:

import android.content.Context;  
import android.widget.Toast;  
  
public class MyUtil {  
     private static Toast mToast;  
     public static void showToast(Context context, int resId, int duration){  
         showToast(context, context.getString(resId), duration);  
     }  
     public static void showToast(Context context, String msg, int duration) {  
             if (mToast == null) {  
                     mToast = Toast.makeText(context, msg, duration);  
             } else {  
                     mToast.setText(msg);  
             }  
             mToast.show();  
     }  
} 

 


文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()