1
I’m creating an app Android
where I have some Switch
which each one is linked to an image. I use a API
to bring them and make your shipment with Image Loader
. When I have an error loading the images I use a Toast
to inform the user. The problem is that when I select several Switch
and there is an error in loading more than one image Toast
remains on screen for a long time, as it enters more than once on Toast
. So I was wondering how can I control the display of this message, showing the Toast
a single time regardless of the number of images with loading error.
Example of the code I’m using to upload the image.
public void loading (){
final Radar finalRadar = radar;
ProductPresenter.getLastData(radar.getRadarId(), new ProductCallBack() {
@Override
public void onSuccess(final Product product) {
final ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.loadImage(product.getUrl(), new ImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
loadImageError(finalRadar.getRadarId(), radar);
return;
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
addRadarOnList(product, finalRadar, loadedImage);
reloadSubtitle(radar);
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
loadImageError(finalRadar.getRadarId(),radar);
}
});
}
@Override
public void onFail() {
loadImageError(finalRadar.getRadarId(),radar);
}
});
}
private void loadImageError(Object componentTag, Radar radar) {
StyleableToast.makeText(context, "Erro ao baixar imagem!", R.style.mytoast).show();
}
You could create an accountant, I think in this case it would work well
– Murillo Comino
@Murillocomino, I have a counter on the switch, counting how many were selected, but if I do an if (counter != 1) Toast.makeText(context, "Error while downloading image!") show(); no loadImageError will not give in the same?
– Regina Moraes