在Android ViewPager上加载图像时,进度条未到达ImageLoadingListener方法内部

时间:2014-02-27 16:07:37

标签: android imageview android-viewpager progress-bar

在我的Android项目中,我使用视图寻呼机来移动图像。图像即将从服务器加载。所以在加载时我想显示一个进度条。为了做同样的事情,我在View Pager的instantiateItem()方法中使用了ImageLoadingListener。但是我观察到进度条没有进入onLoadingStarted()或onLoadingComplete()方法。

这是我的instantiateItem()代码:

    @Override
public Object instantiateItem(ViewGroup container, int position) {
    inflater = (LayoutInflater)context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View viewLayout = inflater.inflate(R.layout.layout_fullscreen_image, container,
            false);
    ImageView imageView = (ImageView) viewLayout.findViewById(R.id.imgDisplay);
    final ProgressBar spinner = (ProgressBar) viewLayout.findViewById(R.id.loading);
    if(thumb_url.get(position) != null)
    {
      imageLoader.DisplayImage(thumb_url.get(position), imageView, new ImageLoadingListener() {

        @Override
        public void onLoadingStarted(String imageUri, View view) {
            // TODO Auto-generated method stub
            Log.d("Testing", "Load started**********************");
        spinner.setVisibility(View.VISIBLE);

        }

        @Override
        public void onLoadingFailed(String imageUri, View view,
                FailReason failReason) {
            // TODO Auto-generated method stub
             spinner.setVisibility(View.GONE);
        }

        @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
            // TODO Auto-generated method stub
            Log.d("Testing", "Load completed");
            spinner.setVisibility(View.GONE);
        }

        @Override
        public void onLoadingCancelled(String imageUri, View view) {
            // TODO Auto-generated method stub
            spinner.setVisibility(View.GONE);
        }
    });
    ((ViewPager) container).addView(viewLayout, 0);
    }
    return viewLayout;
}

此处还有在图像加载过程中调用的方法:

public void DisplayImage(String url, ImageView imageView, ImageLoadingListener imgListener)
{
    Log.d("Testing", "getting the image  "+url);
    imageViews.put(imageView, url);
    Bitmap bitmap=memoryCache.get(url);
    if(bitmap!=null)
    {
        Log.d("Testing", "bitmap is present on the cache ");
         imageView.setImageBitmap(bitmap);
    }

    else
    {
        Log.d("Testing", "bitmap is not present on the cache ");
        queuePhoto(url, imageView);
        imageView.setImageResource(defalt_icon);
    }
}

我无法修复它。任何人都可以帮忙。

谢谢, 阿瑞丹姆。

0 个答案:

没有答案