您的位置:首页 > 移动开发 > Android开发

ToastUtil 多字符串toast 非主线程Toast

2016-08-16 00:00 405 查看
1.多字符串toast,一般用于开发时查知方法运行
2.非主线程中toast


import android.content.Context;
import android.os.Handler;
import android.widget.Toast;

/**
* Created by wangxingsheng on 16/8/10.
*/

public class ToastUtil {
public static void talk(Context context, String... args){
StringBuilder sb = new StringBuilder();
String temp = "";
for (Object obj : args){
if(obj!=null){
temp = obj.toString();
}else{
temp = " *null* ";
}
sb.append(temp);
}
Toast.makeText(context,sb.toString(),Toast.LENGTH_SHORT).show();
}
public static void talkInThread(final Context context, final String... args){
Handler handler = new Handler(context.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
talk(context,args);
}
});
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Android Toast 线程Toast