Toast简单的工具类
2016-05-26 13:50
239 查看
import android.widget.Toast;
/**
* Created by chao0 on 2016/5/26.
*/
public class ToastUtils {
private static Toast toast;
//双重判断确保整个程序只有一个吐司
public static void toastShow(String text){
if (toast==null){
synchronized (ToastUtils.class){
if (toast==null){
toast=Toast.makeText(AppUtils.getBaseContext(),text,Toast.LENGTH_SHORT);
}
}
}else{
toast.cancel();
toast=Toast.makeText(AppUtils.getBaseContext(),text,Toast.LENGTH_SHORT);
}
toast.show();
}
//运行在工作线程的吐司
public static void showWorkThread(final String text){
ThreadPoolUtils.runTaskOnUIThread(new Runnable() {
@Override
public void run() {
toastShow(text);
}
});
}
//运行在ui线程的吐司
public static void showUIThread(String text){
toastShow(text);
}
}
/**
* Created by chao0 on 2016/5/26.
*/
public class ToastUtils {
private static Toast toast;
//双重判断确保整个程序只有一个吐司
public static void toastShow(String text){
if (toast==null){
synchronized (ToastUtils.class){
if (toast==null){
toast=Toast.makeText(AppUtils.getBaseContext(),text,Toast.LENGTH_SHORT);
}
}
}else{
toast.cancel();
toast=Toast.makeText(AppUtils.getBaseContext(),text,Toast.LENGTH_SHORT);
}
toast.show();
}
//运行在工作线程的吐司
public static void showWorkThread(final String text){
ThreadPoolUtils.runTaskOnUIThread(new Runnable() {
@Override
public void run() {
toastShow(text);
}
});
}
//运行在ui线程的吐司
public static void showUIThread(String text){
toastShow(text);
}
}
相关文章推荐
- Java面向对象之多态
- [poj 3070] Fibonacci
- requireJs和r.js压缩工具
- centos6.5 nfs-server 配置实例
- java多线程
- vim常用命令
- Qt布局管理: 堆栈窗体QStackedWidget类(纯代码实现)
- 行业竞争加剧,酷开A2或将杀出一匹黑马?
- HBASE 使用
- gmail smtp 535 5.7.8无法登陆解决
- Servlet + Jsp + Poi 实现 excel 的解析
- 百度应用部署秘籍
- 安卓videoView 横屏,全屏显示
- 使用java的wsimport.exe工具生成wsdl的客户端代码
- mysql数据库体系结构——存储过程
- JMeter对WebService的压力测试
- log4cplus学习
- day12
- Hadoop2.2.0伪分布式中HDFS简述
- 创建虚拟主机目录