I am trying to implement to a list view with all contact images with the help of base adapter and LruCache. But on a long scroll on screen all the images(corresponding to that view) are displayed before setting actual image.
eg: list view with 5 items per page, if we scrolled from first contact to 60th, on first view of list view images of 1,6,11,16,21..51 are displayed for a few milli seconds before the 55th images is shown
Main codes are
//Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = (ImageView) convertView;
if(imageView == null){
imageView = new ImageView(getActivity());
}
int id = contactId[position];
final String imageKey = String.valueOf(contactId);
final Bitmap bitmap = cache.get(imageKey);
if (bitmap != null) {
imageView.setImageBitmap(bitmap);
} else {
Resources res = context.getResources();
BitmapManager bm = new BitmapManager(imageView, res, cache);
bm.setContext(getActivity());
bm.execute(id);
}
return imageView;
}
BitmapManager Post Execute Code
@Override
protected void onPostExecute(Bitmap bitmap) {
// TODO Auto-generated method stub
try{
if(isCancelled()){
bitmap = null;
}
if(imageViewReference != null && bitmap != null){
ImageView imageView = imageViewReference.get();
imageView.setImageBitmap(bitmap);
cache.put(String.valueOf(res), bitmap);
if(imageView != null){
imageView.setImageBitmap(bitmap);
}
}
}catch(Exception e){
}
super.onPostExecute(bitmap);
}
How to solve this problem. Thanks