ListView加载sd卡上的图片,滑动时才显示出来
寒烟凝绿 2015-05-16 05:23:38 数据带过来时 只显示一张 或者不显示图片,只有滑动出屏幕外再滑动回来时 其他的才显示出来
public class UploadAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private WeakHashMap<String, Bitmap> weakHashMap;
private HashMap<String, BitmapCompress> bitmapHashMap;
private List<HashMap<String, String>> list;
public UploadAdapter(Context context,
ArrayList<HashMap<String, String>> arrayList) {
weakHashMap = new WeakHashMap<String, Bitmap>();
this.list = arrayList;
bitmapHashMap = new HashMap<String, BitmapCompress>();
this.mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
HashMap<String, String> hashMap = list.get(position);
ViewHolder holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.listview_photo_upload,
null);
holder.upload_img = (ImageView) convertView
.findViewById(R.id.upload_img);
holder.upload_text = (TextView) convertView
.findViewById(R.id.upload_text);
String id = hashMap.get("id");
bitmap = BitmapFactory.decodeResource(
context.getResources(), 0);
if (weakHashMap.get(id) == null && bitmapHashMap.get(id) == null) {
BitmapCompress bitmapCompress = new BitmapCompress(context,
holder.upload_img, weakHashMap, bitmapHashMap);
bitmapCompress.execute(id);
bitmapHashMap.put(id, bitmapCompress);
} else {
bitmap = weakHashMap.get(id);
holder.upload_img.setImageBitmap(bitmap);
}
holder.upload_text.setText("暂未上传");
return convertView;
}
}