KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a custom adapter which extends ArrayAdapter, it implements the view holder patterns to show data (text + image) from a web service. for lazy loading of the images I use the async tasks pattern from the advanced training in the Android's developers site, I also use disk + ram bitmap cache. when there is additional data to be retrieved I add a footer view that clicking on it retrieves additional data from the web service and add it to the adapter. the problem is that when this new data is being added, some of the visible images are changing and immediately changing back, which result in a weird flickering. other than that everything is working fine and the scrolling is smooth. as far as I understand those image changes are happening when the visible views are being refreshed when new data is added. is there a way to bypass this unwanted behavior ? this is the class doing the downloading and managing the async tasks 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 imageView) { imageViewReference = new WeakReference<ImageView>(imageView); } @Override protected Bitmap doInBackground(String... strings) {
Tags (comma-separated)
Save Edits
Cancel