欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

使用Toast類怎么避免顯示時間疊加

本篇文章給大家分享的是有關使用Toast類怎么避免顯示時間疊加,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

創(chuàng)新互聯(lián)建站專注于巴青網站建設服務及定制,我們擁有豐富的企業(yè)做網站經驗。 熱誠為您提供巴青營銷型網站建設,巴青網站制作、巴青網頁設計、巴青網站官網定制、微信小程序定制開發(fā)服務,打造巴青網絡公司原創(chuàng)品牌,更為您提供巴青網站排名全網營銷落地服務。

具體內容如下

import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.widget.Toast;
 

 
public class ToastUtil {
 
  private static Toast toast = null;
  private static ToastUtil toastUtil = null;
 
  public ToastUtil(){}
 
  public synchronized static ToastUtil getInstance(){
    if(null == toastUtil){
      toastUtil = new ToastUtil();
    }
 
    return toastUtil;
  }
 
  public void showToast(Context context, String string){
 
    if(toast != null){
      toast.cancel();
    }
      toast = Toast.makeText(context, string,Toast.LENGTH_SHORT);
      toast.show();
  }
 
  public void showToast(Fragment fragment, String string){
    showToast(fragment.getActivity(),string);
  }
 
  public void showToast(Activity activity, String string){
    if(toast != null){
      toast.cancel();
    }
    toast = Toast.makeText(activity, string,Toast.LENGTH_SHORT);
    toast.show();
  }
 
  public void showToastTest(Context context){
    if(toast != null){
      toast.cancel();
    }
    toast = Toast.makeText(context, "click",Toast.LENGTH_SHORT);
    toast.show();
  }
 
  public void showToastTest(Fragment fragment){
    showToastTest(fragment.getActivity());
  }
 
  public void showToastTest(Activity activity){
    if(toast != null){
      toast.cancel();
    }
    toast = Toast.makeText(activity, "click",Toast.LENGTH_SHORT);
    toast.show();
  }
}
 
    if(null == toastUtil){
      toastUtil = new ToastUtil();
    }
 
    return toastUtil;
  }
public void showToastInThread(Context context,String msg){
    Looper.prepare();
    if(toast != null){
      toast.cancel();
    }
    toast = Toast.makeText(context,msg,Toast.LENGTH_SHORT);
    toast.show();
    Looper.loop();
  }
  public void showToast(Context context, String string){
 
    if(toast != null){
      toast.cancel();
    }
      toast = Toast.makeText(context, string,Toast.LENGTH_SHORT);
      toast.show();
  }
 
}

這是一個封裝好的Toast工具類,避免時間疊加

使用方法

ToastUtil.getInstance().showToast(mContext,"test");

如果在線程中執(zhí)行的話,必須按照如下格式

ToastUtil.getInstance().showToastInThread(mContext,"str");

以上就是使用Toast類怎么避免顯示時間疊加,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

文章標題:使用Toast類怎么避免顯示時間疊加
鏈接分享:http://chinadenli.net/article4/iphhoe.html

成都網站建設公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)搜索引擎優(yōu)化品牌網站建設定制網站網頁設計公司網站設計公司

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

手機網站建設