I am using volleys NetworkImageView to load image´s in an ArrayAdapter.
For some Items in my Adapter i want to use a Drawable resource instead.
Unfortunally setting the ImageResource doesnt seem to have an effect on NetworkImage.
networkImage.setImageResource(R.drawable.mydrawable); // no effect
I tryed working without NetworkImageView using an ImageLoaders get() method providing an interface. Unfortunally the view recycling didnt work out anymore and image downloads overrode already recycled and reused views.
ImageLoader.ImageListener listener =
ImageLoader.getImageListener(image, R.drawable.loading, R.drawable.error);
ImageCacheManager.getImageLoader().get(url,listener);
// Override´s recycled views image
Any solutions?
If you only want to show drawable and not load any image at all for specific item, this is quite easy:
public void bind(Item item) {
if (item.shouldDisplayDrawable()) {
imageView.setDefaultImageResId(R.drawable.my_drawable); // show your drawable
imageView.setImageUrl(null, app.getImageLoader()); // and if url == null, Volley will not load any image to replace Default
} else {
imageView.setImageUrl(item.getImageUrl(), app.getImageLoader()); // load image from url
}
}
I tried this in my Adapter, recycling works without any issues. And you can continue using
imageView.setDefaultImageResId(R.drawable.icon_image_default);
imageView.setErrorImageResId(R.drawable.icon_image_error);
on imageView you download from url, it will display correct drawable while loading and on error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With