Forgot to paste my code:-

class IconicAdapter extends ArrayAdapter {
Activity context;
Context context2;
HashMap<String,String> ret = new HashMap<String,String>();
AsyncLoader async;// = new AsyncLoader();
private ListView listView;
HashMap<String,Bitmap> bit = new HashMap<String,Bitmap>();


IconicAdapter(Activity context) {
super(context, R.layout.exclusive, items);
this.context=context;
async = new AsyncLoader();
}

public View getView(final int position, View convertView,
ViewGroup parent) {
  View  row_inflated = View.inflate(context, R.layout.exclusive,null);
     wrapper = new ViewWrapper(row_inflated);
     row_inflated.setTag(wrapper);

wrapper.getSongName().setText(items[position]);
wrapper.getSingerName().setText(singer_name[position]);
final ImageView imgview = wrapper.getIcon();
imgview.setTag(myRemoteImages[position]);
Bitmap cachedImage = async.loadDrawable(myRemoteImages[position], new
ImageCallback() {
    public void imageLoaded(Bitmap imageBitmap, String imageUrl) {
       imgview.setImageBitmap(imageBitmap);
            notifyDataSetChanged();
}
    });
if(cachedImage!=null)
    imgview.setImageBitmap(cachedImage);
return(row_inflated);
}
}


======================================================================
AsynLoader is as below:-

public class AsyncLoader{
HashMap<String,Bitmap> bit = new HashMap<String,Bitmap>();
private HashMap<String, SoftReference<Bitmap>> imageCache;
private HashMap<String, SoftReference<Bitmap>> drawableMap;
 public AsyncLoader() {
     drawableMap = new HashMap<String, SoftReference<Bitmap>>();
     imageCache = new HashMap<String, SoftReference<Bitmap>>();
    }
 public Bitmap loadDrawable(final String imageUrl, final ImageCallback
imageCallback) {
     if (drawableMap.containsKey(imageUrl)) {
            SoftReference<Bitmap> softReference = imageCache.get(imageUrl);
            Bitmap drawable = softReference.get();
            if (drawable != null) {
                return drawable;
            }
     }
     final Handler handler = new Handler() {
     @Override
     public void handleMessage(Message message) {
                imageCallback.imageLoaded((Bitmap) message.obj, imageUrl);
     }
     };
     new Thread() {
     @Override
     public void run() {
                Bitmap bitMap = loadImageFromUrl(imageUrl);
                imageCache.put(imageUrl, new SoftReference<Bitmap>(bitMap));
                Message message = handler.obtainMessage(0, bitMap);
                handler.sendMessage(message);
     }
     }.start();
        return null;
    }

    public static Bitmap loadImageFromUrl(String url){


     URL aURL;
     Bitmap bitmap=null;//=this.bm;
     try {
aURL = new URL(url);
URLConnection conn;
conn = aURL.openConnection();
conn.connect();
  InputStream is= conn.getInputStream();
  BufferedInputStream bis = new BufferedInputStream(is);
     bitmap = BitmapFactory.decodeStream(bis);
    // bitMap.put(p,bm);
     bis.close();
         is.close();


} catch (MalformedURLException e) {
 e.printStackTrace();
} catch (IOException e) {
 e.printStackTrace();
}
return bitmap;
    }

    public interface ImageCallback {
        public void imageLoaded(Bitmap imageBitmap, String imageUrl);
    }
}


Thanks,
Prajakta



On Sat, Apr 10, 2010 at 10:21 AM, praj <[email protected]> wrote:

> Hi,
>
> I was trying to implement the lazy loading of images in the list view.
> For implementing this i was referring to post by Tom van Zummeren.
> (http://blog.jteam.nl/2009/09/17/exploring-the-world-of-android-
> part-2/), but my images keep on changing in the list. Please can
> anyone let me know if they were able to get this working properly
> without having the images drawn again and again or let me know if I
> have missed on anything or doing something wrong.
>
> Thanks,
> Prajakta
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>
> To unsubscribe, reply using "remove me" as the subject.
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to