Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: showing default image in gallery's ImageView while actual image is downloaded
    text
    copied!<p>I believe this is pretty trivial but I can't get it to work.<br> I want to display a default image in gallery elements (ImageViews) while their actual image is being fetched from the net.<br> Right now, nothing is shown for an ImageView which its image has yet to arrive. Once it arrives it is immediately shown.<br> What I tried is right after the instantiation of the ImageView to call its setImageResource function like so: </p> <p>final ImageView i = new ImageView(mContext);<br> i.setImageResource(R.drawable.loading);</p> <p>But it doesn't seem to work. Below is the full getView() function.<br> Any help is appreciated.<br> Thanks.</p> <pre><code>public View getView(int position, View convertView, ViewGroup parent) { final ImageView i = new ImageView(mContext); i.setImageResource(R.drawable.loading); // if the drawbale is in the buffer - fetch it from there Drawable bufferedImage = DataManager.getInstance().getImagesBuffer()[position]; if (bufferedImage != null){ i.setImageDrawable(bufferedImage); BitmapDrawable drawable = (BitmapDrawable) i.getDrawable(); drawable.setAntiAlias(true); } // if drawable is not in buffer - fetch it from the net via AsyncImageLoader else { String imageUrl = DataManager.getInstance().getImageBufferInstance().getImageUrl(position); Drawable downloadedImage = AsyncImageLoader.getInstance().loadDrawable(imageUrl, new ImageCallback() { public void imageLoaded(Drawable imageDrawable, String imageUrl) { if (imageDrawable == null) { imageDrawable = getResources().getDrawable(R.drawable.icon); } i.setImageDrawable(imageDrawable); BitmapDrawable drawable = (BitmapDrawable) i.getDrawable(); drawable.setAntiAlias(true); } }); i.setImageDrawable(downloadedImage); } i.setLayoutParams(new CoverFlow.LayoutParams(Utils.getInstance().getScreenWidth() / 2, Utils.getInstance().getScreenHeight() / 2)); i.setScaleType(ImageView.ScaleType.CENTER_INSIDE); return i; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload