0

I have a custom Gridview. In my adapter asynchronous image downloading done using AQuery. images are downloaded properly but in some cases error will occur so that time imageView background goes totaly white.i want to set that error image.

Now here is the code of my adapter in gridView():

try{
            String[] tmp_arr_thumb_img = prodItems.get(holder.position).getprod_image().split(global.split_seprator);
            //String imageID = tmp_arr_thumb_img[0];
            String thumbImg = tmp_arr_thumb_img[1];

            if (aQuery.shouldDelay(holder.position, convertView, parent, global.GLOBAL_UPLOADED_PHOTOS_URL + thumbImg)){
                aQuery.id(holder.imageView).image(R.drawable.no_image);
            }else{
                aQuery.id(holder.imageView)
                        .image(global.GLOBAL_UPLOADED_PHOTOS_URL + thumbImg,true,true,200,0, new BitmapAjaxCallback(){
                            @Override
                            protected void callback(String url, ImageView iv, Bitmap bm, AjaxStatus status) {

                                iv.setImageBitmap(bm);
                            }
                        }.animation(AQuery.FADE_IN));
            }
        }catch (OutOfMemoryError err){
            err.printStackTrace();
        }

2 Answers2

0

Please update your code with this wil use a place holder imaage

aQuery.id(holder.imageView)
                    .image(global.GLOBAL_UPLOADED_PHOTOS_URL + thumbImg,true,true,200,R.drawable.placeholder, new BitmapAjaxCallback(){
                        @Override
                        protected void callback(String url, ImageView iv, Bitmap bm, AjaxStatus status) {

                            iv.setImageBitmap(bm);
                        }
                    }.animation(AQuery.FADE_IN));
Vishnu V S
  • 355
  • 1
  • 10
0

If we are not able to load the image, use a default image (R.drawable.default_image)

String imageUrl = "http://www.vikispot.com/z/images/vikispot/android-w.png";
aq.id(R.id.image1).image(imageUrl, true, true, 0, R.drawable.default_image);

Make image view "invisible" if image failed to load

imageUrl = "http://a.b.com/invalid.jpg"; 
aq.id(R.id.image1).image(imageUrl, true, true, 0, AQuery.INVISIBLE);

Make image view "gone" if image failed to load

aq.id(R.id.image1).image(imageUrl, true, true, 0, AQuery.GONE);
Kyle Howells
  • 3,008
  • 1
  • 25
  • 35
Mohan
  • 311
  • 8
  • 15