I have an app that downloads a bunch of images in a background thread. As each icon gets downloaded, I add it to an ArrayList in my custom Adapter which subclasses BaseAdapter. Each row in the ListView that uses the BaseAdapter has an ImageView. In getView, I do the following.
public View getView(int position, View convertView, ViewGroup parent) {
final MyCustomImageClass imageObject = data.get(position);
View vi = convertView;
if(convertView==null) {
vi = inflater.inflate(R.layout.list_row, null);
}
ImageView thumbnail = (ImageView)vi.findViewById(R.id.list_image);
File appDir = new File(Utils.getAppFilesDir() +"");
File imageFolder = new File(appDir, imageObject.getImageFolderName());
File imageDir = new File(imageFolder, imageObject.getIconFilename());
Log.e("myapp", "row image dir: " + imageDir.toString());
if(imageDir.exists()) {
Bitmap imageBitmap = BitmapFactory.decodeFile(imageDir.toString());
thumbnail.setImageBitmap(imageBitmap);
}
thumbnail.invalidate();
}
But what I'm seeing is that thumbnail
is re-using old images. Like, the first few rows will have the same thumbnail image even though I see a different path for them in logcat.
How do I tell the row in a ListView that its ImageView has a new Bitmap image?