繁体   English   中英

Listview动态加载的图像-第一个列表项显示了listview中加载的所有图像,然后清除

[英]Listview dynamically loaded images - First list items shows all images loaded in the listview and then clears out

因此,我从每个listview项目的URL动态加载图像。

问题:

我似乎有一个错误,在加载列表视图时,第一个列表视图项的ImageView会闪烁显示所有列表视图项的所有图像。 它们全部加载后,listview项将逐个显示其图像,第一个将获得其适当的图像。

我不确定发生了什么,为什么会这样。

这是我的图像加载AsyncTask。

private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
    private final WeakReference bmImage;

    public DownloadImageTask(ImageView image) {
        bmImage = new WeakReference(image);
    }

    protected Bitmap doInBackground(String... urls) {
        String urldisplay = urls[0];
        Bitmap mIcon11 = null;
        try {
            InputStream in = new java.net.URL(urldisplay).openStream();
            mIcon11 = BitmapFactory.decodeStream(in);
        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        return mIcon11;
    }

    protected void onPostExecute(Bitmap bitmap ) {
        if (isCancelled()) {
            bitmap  = null;
        }

        if (bmImage != null) {
            ImageView imageView = (ImageView)bmImage.get();

            // if the imageView was not retrieved
            if (imageView != null) {

                // if the image source is not empty
                if(bitmap != null){
                    imageView.setImageBitmap(bitmap);
                }else{
                    // set placeholder image
                    imageView.setImageDrawable(imageView.getContext().getResources()
                            .getDrawable(R.drawable.social_eyes_bare_owl));
                }
            }
        }
    }
}

我在使用类似的图像下载器时遇到了同样的问题。 问题可能不在下载器中,而是在您从中提供URL的地方。 因此,如果可以的话,您可以更新调用此图像加载器的代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM