ListView显示空白空间而不是本地图像
问题描述:
我想加载一个列表只有本地图像和文本,一切工作正常,我的意思是我可以看到文本很好,但在图像领域我看不到图片。ListView显示空白空间而不是本地图像
的本地图片的路线是“/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();
非常感谢。
答
对我而言,这是帮助较少的信息。代码中缺少的是填充项目ArrayList。
当显示文本并且不显示照片时,这意味着输入了最后一个if-子句。尝试将Log-Output放入最后一个if子句并输出您使用的URI。
亲切的问候
+0
所有答案都认为URI可能是错误的。请记录它们。 – ChrLipp
答
的URI的文件必须以“文件://”,让您的seturi也许应该是:
objExpediente.setUriPath(Uri.parse("file://" + cur.getString(cur.getColumnIndex("Path")) + cur.getString(cur.getColumnIndex("_id")) + ".jpg"));
在其中添加图像URI来的ArrayList? –
我更新了信息。谢谢 – carlosrah
确保通过logcat检查你的数组列表是否有项目。 –