|
我是参考这篇文章来的:http://www.eoeandroid.com/thread-10497-1-1.html
但是我遇到个问题,无法正确的显示,代码如下:
package com.android.bjhy.rollCall.pub;
import java.util.List;
import java.util.Map;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.widget.ImageView;
import android.widget.SimpleAdapter;
public class MySimpleAdapter extends SimpleAdapter{
public MySimpleAdapter(Context context,
List<? extends Map<String, ?>> data, int resource, String[] from,
int[] to) {
super(context, data, resource, from, to);
// TODO Auto-generated constructor stub
}
@Override
public void setViewImage(ImageView v, String value) {
// TODO Auto-generated method stub
Bitmap bitmap = BitmapFactory.decodeFile(value); //value是我传进来的图片文件的路径
int width=60;
int height=60;
Bitmap newBitmap=ImageUtil.resizeImage(bitmap, width, height); //我这里是缩放bitmap到60x60
v.setImageBitmap(newBitmap); // 跟新到ImageView即可
}
}
这是我定义的适配器,activity 代码
List<rison> prisons = prisonService.getAllPrison();//获取结果集
ArrayList<HashMap<String, Object>> lstImageItem = new ArrayList<HashMap<String, Object>>();
for(Prison prison : prisons){
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("itemImage", prison.getZp());
map.put("itemText", prison.getXm());
lstImageItem.add(map);
}
MySimpleAdapter mySimpleAdapter = new MySimpleAdapter(RollCallActivity.this,lstImageItem, R.layout.prisonitem, new String[] { "itemImage", "itemText" }, new int[] { R.id.itemImage, R.id.itemText });
gridview.setAdapter(mySimpleAdapter);
我觉得是我的逻辑有问题,请大哥们指点下小弟,刚接触这个东西,setViewImage这个方法没调用到,不知道如何下手! |
|