1、 核心思想
private Toast toast;
if (toast == null)
toast = Toast.makeText(CityManager.this, "定位出错", Toast.LENGTH_SHORT);
toast.show();
2、 提取toast工具
在要使用时,这样调用
ToastUtil.getToast(getApplicationContext(),”定位错了”);
public class ToastUtil {
private static Context context = null;
private static Toast toast = null;
public static void getToast(Context context,StringretId){
if (toast == null) {
toast = Toast.makeText(context, retId, Toast.LENGTH_SHORT);
} else {
toast.setText(retId);
toast.setDuration(Toast.LENGTH_SHORT);
}
toast.show();
}
}