R
- The type of resource being loaded.public interface RequestListener<R>
Modifier and Type | Method and Description |
---|---|
boolean |
onLoadFailed(GlideException e,
Object model,
Target<R> target,
boolean isFirstResource)
Called when an exception occurs during a load, immediately before
Target.onLoadFailed(Drawable) . |
boolean |
onResourceReady(R resource,
Object model,
Target<R> target,
DataSource dataSource,
boolean isFirstResource)
Called when a load completes successfully, immediately before
Target.onResourceReady(Object, com.bumptech.glide.request.transition.Transition) . |
boolean onLoadFailed(@Nullable GlideException e, Object model, Target<R> target, boolean isFirstResource)
Target.onLoadFailed(Drawable)
. Will only be called if we currently want to display an
image for the given model in the given target. It is recommended to create a single instance
per activity/fragment rather than instantiate a new object for each call to Glide.load()
to avoid object churn.
It is safe to reload this or a different model or change what is displayed in the target at this point. For example:
public void onLoadFailed(Exception e, T model, Target target, boolean isFirstResource) {
target.setPlaceholder(R.drawable.a_specific_error_for_my_exception);
Glide.load(model).into(target);
}
Note - if you want to reload this or any other model after an exception, you will need to include all relevant builder calls (like centerCrop, placeholder etc).
e
- The maybe null
exception containing information about why the
request failed.model
- The model we were trying to load when the exception occurred.target
- The Target
we were trying to load the image into.isFirstResource
- true
if this exception is for the first resource to load.true
if the listener has handled updating the target for the given exception,
false
to allow Glide's request to update the target.boolean onResourceReady(R resource, Object model, Target<R> target, DataSource dataSource, boolean isFirstResource)
Target.onResourceReady(Object, com.bumptech.glide.request.transition.Transition)
.resource
- The resource that was loaded for the target.model
- The specific model that was used to load the image.target
- The target the model was loaded into.dataSource
- The DataSource
the resource was loaded from.isFirstResource
- true
if this is the first resource to in this load to be
loaded into the target. For example when loading a thumbnail and a
full-sized image, this will be true
for the first image to
load and false
for the second.true
if the listener has handled setting the resource on the target,
false
to allow Glide's request to update the target.
Setting the resource includes handling animations, be sure to take that into account.