Android Glide: prevent white image if the request fails -
so i'm interested if prevent glide loading white (null) image imageview if url provided wrong.. i'd keep image provide in xml if can't find image (because might wrong due user input).
i've tried returning true in listener, guess that's animation handling. many thanks!
public static void loadimage(string url, context c, imageview target) { glide.with(c).load(url).listener(new requestlistener<string, glidedrawable>() { @override public boolean onexception(exception e, string model, target<glidedrawable> target, boolean isfirstresource) { e.printstacktrace(); return true; } @override public boolean onresourceready(glidedrawable resource, string model, target<glidedrawable> target, boolean isfrommemorycache, boolean isfirstresource) { return false; } }).into(target); }
}
you can use .error(mdefaultbackground) --> sets drawable display if load fails.
keep image. below
drawable mdefaultbackground = getresources().getdrawable(r.drawable.default_background); glide.with(getactivity()) .load(uri) .centercrop() .error(mdefaultbackground).into(target);
from documentation
Comments
Post a Comment