相关疑难解决方法(0)

Android:将数据添加到ArrayAdapter时,可见的ListView图像闪烁

我有一个扩展ArrayAdapter的自定义适配器,它实现了视图持有者模式,以显示来自Web服务的数据(文本+图像).

对于延迟加载图像我使用Android开发者网站中高级培训的异步任务模式,

我还使用disk + ram位图缓存.

当有其他数据需要检索时,我添加了一个页脚视图,点击它可以从Web服务中检索其他数据并将其添加到适配器.

问题是,当添加这些新数据时,一些可见图像正在改变并立即改回,这导致奇怪的闪烁.

除此之外一切正常,滚动顺畅.

据我所知,当添加新数据时刷新可见视图时会发生这些图像更改.

有没有办法绕过这种不受欢迎的行为?

这是执行下载和管理异步任务的类

public class ImageDownloader {
private ImageCache mCache;
private int reqWidth;
private int reqHeight;

public void download(String url, ImageView imageView, ImageCache imageCache, int reqHeight, int reqWidth) {
    mCache = imageCache;
    this.reqHeight = reqHeight;
    this.reqWidth = reqWidth;

    if (cancelPotentialDownload(url, imageView)) {
        BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);

        DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
        imageView.setImageDrawable(downloadedDrawable);
        task.execute(url);
    }
}

private class BitmapDownloaderTask extends AsyncTask<String, Void, Bitmap> {
    private String url;
    private WeakReference<ImageView> imageViewReference;

    public BitmapDownloaderTask(ImageView …
Run Code Online (Sandbox Code Playgroud)

android android-listview android-adapter android-asynctask cwac-endless

8
推荐指数
1
解决办法
6705
查看次数