如图所示,
修改之前:
修改之后:
解决方案:
通过判定吐司是否为null,如果为null那么重新创建一个新的Toast,否则直接引用以前的。很简单吧。
public class ToastUtil {
private static Context context = null;
private static Toast toast = null;
public static void getToast(Context context,int retId){
if (toast == null) {
toast = Toast.makeText(context, retId, Toast.LENGTH_SHORT);
} else {
toast.setText(retId);
toast.setDuration(Toast.LENGTH_SHORT);
}
toast.show();
}
}