【问题标题】:onLoadingComplete Universal Imageloader not called未调用 onLoadingComplete 通用图像加载器
【发布时间】:2014-02-28 07:08:18
【问题描述】:

我必须在图像加载后立即做一些事情。我正在使用SimpleImageLoadingListener 来监听回调方法,但奇怪的是onLoadingComplete 从未被调用,但onLoadingStarted 会。我已经检查过没有调用图像加载失败或取消方法——这意味着没有错误。任何人都可以指出原因和纠正它的步骤。谢谢。

 public View getView(int position, View convertView, ViewGroup parent) {

         ImageView img = new ImageView(mContext);
         img.setLayoutParams(new Gallery.LayoutParams(coverflowWidth, coverflowHeight));
         img.setScaleType(ScaleType.CENTER_INSIDE);
         img.setTag(position);

        ImageLoader.getInstance().displayImage(imageURL, img, options,  new SimpleImageLoadingListener()

        {
            boolean cacheFound;

            @Override
            public void onLoadingStarted(String url, View view) {
                List<String> memCache = MemoryCacheUtil.findCacheKeysForImageUri(url, ImageLoader.getInstance().getMemoryCache());
                cacheFound = !memCache.isEmpty();
                if (!cacheFound) {
                    File discCache = DiscCacheUtil.findInCache(url, ImageLoader.getInstance().getDiscCache());
                    if (discCache != null) {
                        cacheFound = discCache.exists();
                    }
                }
            }

            @Override
            public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {

          //never gets called
                ImageView image = (ImageView) view;

                if (cacheFound) {

                image.setImageBitmap(loadedImage);

               }

                else
                {
                    ImageLoader.getInstance().displayImage(imageURL, image, options, null);
                }   

            }
        });

     return img;

 }

【问题讨论】:

    标签: android universal-image-loader


    【解决方案1】:

    我实际上是在请求从不同的地方加载相同的图像 2 次。所以onLoadingComplete 被调用另一个代码sn-p,而不是我上面提到的那个。愚蠢的我……这是一个愚蠢的错误。

    【讨论】:

      【解决方案2】:

      在我的情况下,我将 filepath 作为字符串传递,而它要求将 filePath 的 URI 作为ImageLoader.getInstance().displayImage(imageURL, img, options, new SimpleImageLoadingListener()) 的第一个参数;

      【讨论】:

        猜你喜欢
        • 2014-12-28
        • 1970-01-01
        • 2015-04-25
        • 2015-04-11
        • 2013-08-04
        • 1970-01-01
        • 2013-06-11
        • 2017-04-07
        • 1970-01-01
        相关资源
        最近更新 更多