I create in a loop dynamically ImageView on the list of links to pictures. When you first start pictures are not displayed, when you restart displayed. What could be wrong and how to fix it?

It feels like while the pictures are loading, that they manage to fall asleep before displaying the pictures, and the second time it just takes from the cache: /

for (int z = 0; z < zCont.length; z++) { LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(100, 100); params.gravity= Gravity.LEFT; ImageView iv = new ImageView(this); iv.setScaleType(ImageView.ScaleType.FIT_XY); setImage(iv, "http://sait.ru/fotota/foto"+tel+".jpeg"); linearLayout.addView(iv, params); } private void setImage(final ImageView imageView, final String imgURL) { Picasso.with(this) .load(imgURL) .error(R.mipmap.ic_launcher) .into(new Target() { @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { Log.e("loaded", "onBitmapLoaded: loaded" ); imageView.setImageBitmap(bitmap); imageView.invalidate(); } @Override public void onBitmapFailed(Drawable errorDrawable) { Log.e("loaded", "onBitmapFailed: load failed" ); } @Override public void onPrepareLoad(Drawable placeHolderDrawable) { } }); } 
  • This should work on the idea. Try adding ImageView to your markup first and then starting the download. Well, it is not clear we will use Target. Try to load without it immediately in ImageView - YuriySPb
  • @ ЮрийСПб Thanks! Replacing Target with ImageView really helped, everything was loaded as it should. Give the answer, I will mark it as the best. - Gennady

1 answer 1

Try downloading a picture in the usual way without using Target, i.e. something like this:

 Picasso.with(this) .load(imgURL) .error(R.mipmap.ic_launcher) .into(imageView);