Android ListView显示空白区域而不是本地图像
我正在尝试加载一个仅包含本地图像和文本的列表,一切正常,我的意思是我可以很好地看到文本,但在图像字段中我看不到图像 本地映像路由为“/mnt/sdcard/Imagenes/pic1.jpg/”、“/mnt/sdcard/Imagenes/pic2.jpg/”等 我一定是做错了什么,弄不清楚是什么。任何帮助都将不胜感激,谢谢 下面是我如何将适配器设置为列表的Android ListView显示空白区域而不是本地图像,android,listview,android-listview,android-image,android-adapter,Android,Listview,Android Listview,Android Image,Android Adapter,我正在尝试加载一个仅包含本地图像和文本的列表,一切正常,我的意思是我可以很好地看到文本,但在图像字段中我看不到图像 本地映像路由为“/mnt/sdcard/Imagenes/pic1.jpg/”、“/mnt/sdcard/Imagenes/pic2.jpg/”等 我一定是做错了什么,弄不清楚是什么。任何帮助都将不胜感激,谢谢 下面是我如何将适配器设置为列表的 FotosAdapter FotoAdapter = new FotosAdapter(this, R.layout.galeriafot
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;
}
}
非常感谢。对我来说,帮助我的信息太少了。代码中缺少的是填写items ArrayList 当显示文本而不显示照片时,这意味着输入了最后一个if子句。尝试将日志输出放入最后一个if子句,并输出您使用的URI
文件的URI必须以“file://”开头,因此您的seturi可能应该是:
objExpediente.setUriPath(Uri.parse("file://" + cur.getString(cur.getColumnIndex("Path")) + cur.getString(cur.getColumnIndex("_id")) + ".jpg"));
将图像URI添加到arraylist的位置?确保通过logcat检查arraylist是否有项。是的,数组有元素,我可以看到文本部分,我只是看不到图像可能是尾随的“/”?问题是我试图显示完整的图像,我必须在加载之前调整图像的大小。谢谢大家…所有答案都认为URI可能是错误的。请把它们记录下来。
objExpediente.setUriPath(Uri.parse("file://" + cur.getString(cur.getColumnIndex("Path")) + cur.getString(cur.getColumnIndex("_id")) + ".jpg"));