1

Grid view using universal image load, when I debug find the getView method called many times even mImageUrlList just have one item. And in Onloadingcomplete method, tempSelectBitmap arraylsit add superfluous repeat images. I have no idea what wrong ?

public class SellCarPictureGalleryAdapter extends BaseAdapter{
    private Context activity;
    private LayoutInflater inflater;
    private ArrayList<String> mImageUrlList;
    private boolean shape;
    private  ViewHolder holder;
    Bimp bimp;
    ImageItem imageItem;
    private static AppController mAppController= AppController.getInstance();
    private int carId;
    static ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(mAppController)
            .memoryCacheSize(41943040)
            .diskCacheSize(104857600)
            .threadPoolSize(10)
            .build();
    static DisplayImageOptions imgDisplayOptions = new DisplayImageOptions.Builder()
            .cacheInMemory()
            .cacheOnDisk(true)
            .build();
    static ImageLoader imageLoader=ImageLoader.getInstance();

    public boolean isShape() {
        return shape;
    }

    public void setShape(boolean shape) {
        this.shape = shape;
    }

    public SellCarPictureGalleryAdapter(Context context,ArrayList<String> mImageUrlList) {
        imageLoader.init(config);
        this.activity=context;
       this.mImageUrlList=mImageUrlList;
        inflater = LayoutInflater.from(context);
    }

  @Override
    public int getCount() {

        return mImageUrlList.size();
    }
    @Override
    public Object getItem(int arg0) {
        return mImageUrlList.get(arg0);
    }
    @Override
    public long getItemId(int postion) {
        return postion;
    }


    public View getView(final int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            v = inflater.inflate(R.layout.item_published_grida,
                    parent, false);
            holder = new ViewHolder();
            holder.image = (ImageView) v
                    .findViewById(R.id.item_grida_image);
            v.setTag(holder);
        } else {
            holder = (ViewHolder) v.getTag();
        }

        //"/data/data/com.zhixiangzhonggong.tiebaobei/app_imageDir"+ "/"
        String filePath = new String("file:///"+mImageUrlList.get(position));

        imageLoader.displayImage(filePath, holder.image, imgDisplayOptions, new ImageLoadingListener() {
            @Override
            public void onLoadingStarted(String s, View view) {

            }

            @Override
            public void onLoadingFailed(String s, View view, FailReason failReason) {

            }

            @Override
            public void onLoadingComplete(String s, View view, Bitmap bitmap) {

                    bimp = new Bimp();
                    imageItem = new ImageItem();
                    imageItem.setBitmap(bitmap);

                    bimp.tempSelectBitmap.add(imageItem);


            }

            @Override
            public void onLoadingCancelled(String s, View view) {

            }
        });
        return v;
    }

    public class ViewHolder {
        public ImageView image;
    }
}
Buddy
  • 10,874
  • 5
  • 41
  • 58
Gang Luo
  • 51
  • 6

0 Answers0