Download various offline images (default images) in NetworkImageview Volley android

What i have

For me GridLayoutManager Recyclerview, for which the positions 0,2,5,7 are fixed with custom images (the relative layout is converted to a bitmap ;) ), the rest positions are filled with images from the server using volley setImageUrl ()

What I want

I wanted to GridLayoutManager Recyclerviewdisplay offline images from my dropdown using setDefaultImageResId () until the images from the server loaded

My problem

How to set different default images, even if there are no images from the server (when there is no data from the server, it GridLayoutManager Recyclerviewdoes not fill the cells) , nevertheless I wanted to display images by default (at least 4 cells are required)

temporary trick i did

I uploaded 4 default images to a dummy server to force GridLayoutManager Recyclerviewcells to be generated and showing it with volley setImageUrl ()

Expected Result

enter image description here

+4
source share
2 answers

I think volleyball has the ability to display the default image and the image if an error occurs.

NetworkImageView niv = (NetworkImageView)findViewById(R.id.niv);
if(url.length() > 0) 
    niv.setImageUrl(url, imageLoader);
niv.setDefaultImageResId(R.drawable._default);
niv.setErrorImageResId(R.drawable.error);
0

Picasso . Picasso, , , .

Picasso.with(context).load(url).error(R.drawable.error_or_defaultimage).into(R.id.imageview,callback) ;

Picasso.

0

Source: https://habr.com/ru/post/1629178/


All Articles