How to use NetworkImageView in a ListView

浪子不回头ぞ 提交于 2019-12-02 07:58:58

问题


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);
    }}

回答1:


If you are trying to load image into ListView's item, you should do it in the Adapter's getView() method. Check this example. It should help you.



来源:https://stackoverflow.com/questions/23142734/how-to-use-networkimageview-in-a-listview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!