【发布时间】:2011-09-19 10:11:21
【问题描述】:
我正在尝试加载仅包含本地图像和文本的列表,一切正常,我的意思是我可以很好地看到文本,但在图像字段中我看不到图像。
本地图片路由为“/mnt/sdcard/Imagenes/pic1.jpg/”、“/mnt/sdcard/Imagenes/pic2.jpg/”等
我一定是在这里做错了什么,无法弄清楚是什么。任何帮助将不胜感激,谢谢...
这是我如何将适配器设置为列表
FotosAdapter FotoAdapter = new FotosAdapter(this, R.layout.galeriafotos, listafotos);
listado.setAdapter(FotoAdapter);
和适配器
public class FotosAdapter extends ArrayAdapter<Foto> {
private ArrayList<Foto> items;
public FotosAdapter(Context context, int textViewResourceId, ArrayList<Foto> items) {
super(context, textViewResourceId, items);
this.items = items;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ContenedorVista contenedor;
if (convertView == null) {
LayoutInflater infla = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infla.inflate(R.layout.galeriafotos, null);
contenedor = new ContenedorVista();
contenedor.txtObservacion = (TextView) convertView.findViewById(R.id.observaciones);
contenedor.imgFotos = (ImageView) convertView.findViewById(R.id.fotosexpediente);
convertView.setTag(contenedor);
}else{
contenedor = (ContenedorVista)convertView.getTag();
}
Foto o = items.get(position);
if (o != null) {
contenedor.txtObservacion.setText(o.getObservaciones());
contenedor.imgFotos.setImageURI(o.getUriPath());
}
return convertView;
}
static class ContenedorVista{
TextView txtObservacion;
ImageView imgFotos;
}
}
这是我设置数组的方式。
listafotos = new ArrayList();
ImagesAdapter ia = new ImagesAdapter(Common.dbAdapter.getDatabase());
Cursor cur = ia.getFiltered(-1, -1, CodExp, null, null, Common.currentUser.getIdUsuario());
cur.moveToFirst();
while(!cur.isAfterLast()){
try{
Foto objExpediente = new Foto();
objExpediente.setUriPath(Uri.parse(cur.getString(cur.getColumnIndex("Path")) + cur.getString(cur.getColumnIndex("_id")) + ".jpg"));
objExpediente.setObservaciones(cur.getString(cur.getColumnIndex("Observaciones")));
listafotos.add(objExpediente);
}catch(Exception ex){
Common.log("e",ex.toString());
}
cur.moveToNext();
}
cur.close();
非常感谢。
【问题讨论】:
-
您在哪里将图像 uri 添加到 arraylist?
-
确保通过 logcat 检查您的数组列表是否有项目。
-
是的,数组有元素,我可以看到文本部分,我只是看不到图像
-
可能是尾随的'/'?
-
问题是我试图显示完整的图像,我必须在加载之前调整图像大小。谢谢大家...
标签: android listview android-listview android-image android-adapter