使用UniversalImageLoader的ListView不更新图像

时间:2015-10-02 04:54:50

标签: android listview universal-image-loader

我有ListView个自定义ListAdapter

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageSize;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;

import java.util.ArrayList;

/**
 * Created by Tukajo on 10/1/2015.
 */
public class CharacterListAdapter extends ArrayAdapter<Character> implements ResourceDownloader.OnTaskCompleted {
    private ImageView charImgView = null;

    public CharacterListAdapter(Context context, int textViewResourceId) {
        super(context, textViewResourceId);
    }

    public CharacterListAdapter(Context context, int resource, ArrayList<Character> items) {
        super(context, resource, items);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View v = convertView;
        if (v == null) {
            LayoutInflater vi;
            vi = LayoutInflater.from(getContext());
            v = vi.inflate(R.layout.custom_character_list_row, null);
        }

        Character p = getItem(position);
        charImgView = (ImageView) v.findViewById(R.id.characterImageView);
        if (p != null) {
            ImageSize targetSize = new ImageSize(200, 200);
            ImageLoader imageLoader = ImageLoader.getInstance();
            DisplayImageOptions options = new DisplayImageOptions.Builder().showImageOnLoading(R.drawable.ic_person_brown_600_48dp)
                    .showImageForEmptyUri(R.drawable.ic_person_brown_600_48dp)
                    .showImageOnFail(R.drawable.ic_person_brown_600_48dp)
                    .cacheInMemory(false)
                    .cacheOnDisk(true)
                    .build();
            imageLoader.loadImage(p.getPhoto(), targetSize, options, new SimpleImageLoadingListener() {
                @Override
                public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                    charImgView.setImageBitmap(loadedImage);
                }
            });

        }

        return v;
    }

    @Override
    public void onTaskCompleted(Bitmap bitmap) {
        charImgView.setImageBitmap(bitmap);
    }
}

无论运行列表,我都会在存储中获取“加载”图像,但默认的drawable仍在加载。

以下是我的意思截图:

enter image description here

0 个答案:

没有答案