Can I know if there is any method that I can use to do something when loading placeholder to the Glide. Here I have set a firebase
image url to setBitmap
method using Glide
. if resource available setBitmap
method will run. If it is not available I want to run a another method. Is there a method something like onLoadingPlaceholder()
?
Glide.with(getApplicationContext()).asBitmap()
.load(dataSnapshot.child("imageUrl").getValue(String.class))
.apply(new RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.image)
.error(R.drawable.image))
.into(new CustomTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
Log.d(TAG, "onResourceReady: ");
setBitmap(resource);
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {}
});
Simply What I need to do is that, set a bitmap when placeholder load. So I need to set a default image when firebase
image is not available.
Finally, I found the answer. But it is not something like onLoadPlaceholder()
, This works for me!
String imageUrl = dataSnapshot.child("imageUrl").getValue(String.class);
if(imageUrl==null){
setBitmap(resource);
}
Glide.with(getApplicationContext()).asBitmap()
.load(imageUrl)
.apply(new RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.contatctmani)
.error(R.drawable.contatctmani))
.into(new CustomTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
setBitmap(resource);
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {}
});