I am new in Android and I got stuck on something. I have a LisView and I am trying to download images using NetworkImageView, but I can't manage to do it.
I have this in onCreate method:
networkImageView = (NetworkImageView) findViewById(R.id.thumbImageUrl);
mRequestQueue = Volley.newRequestQueue(this);
imageLoader = new ImageLoader(mRequestQueue, new BitmapLruCache(BitmapLruCache.getDefaultLruCacheSize()));
networkImageView.setImageUrl(IMAGE_URL, imageLoader);
but it doesn't work and I don't know why.
Can anybody tell me how to do it? I think I didn't understood too well how to use NetworkImageView.
PS: my BitmapLruCache.java
public class BitmapLruCache extends LruCache<String, Bitmap> implements ImageCache {
public static int getDefaultLruCacheSize() {
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
final int cacheSize = maxMemory / 8;
return cacheSize;
}
public BitmapLruCache() {
this(getDefaultLruCacheSize());
}
public BitmapLruCache(int sizeInKiloBytes) {
super(sizeInKiloBytes);
}
@Override
protected int sizeOf(String key, Bitmap value) {
return value.getRowBytes() * value.getHeight() / 1024;
}
@Override
public Bitmap getBitmap(String url) {
return get(url);
}
@Override
public void putBitmap(String url, Bitmap bitmap) {
put(url, bitmap);
}}
来源:https://stackoverflow.com/questions/23142734/how-to-use-networkimageview-in-a-listview