0

カスタム Gridview があります。私のアダプターでは、AQuery を使用して画像の非同期ダウンロードを行いました。画像は正常にダウンロードされますが、場合によってはエラーが発生し、imageView の背景が真っ白になることがあります。そのエラー画像を設定したいと考えています。

ここで、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();
        }
4

2 に答える 2

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);
于 2016-07-15T07:01:29.750 に答える
0

これでコードを更新してください。これはプレースホルダーのイメージを使用します。

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));
于 2016-07-15T06:47:47.027 に答える