我有 GridView 适配器,我想通过照片的 URL 从 Firebase 存储下载照片。
当我将 URL 传递给 GridViewAdapter 时,照片是空白的。有空间,但没有图片。就像透明图片一样。
如果我传递在 Google 中找到的图像网址,它可以工作,但它不适用于 Firebase Storage 的网址。怎么了?
这是我尝试从 Firebase Storage 获取网址的方法 我正在获取包含所有 URL 的节点的 DataSnapshot
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
photos.clear();
for(DataSnapshot ds: dataSnapshot.getChildren()){
String photoURL = ds.getValue(String.class);
try {
photos.add(photoURL);
}catch (NullPointerException e) {
}
}
gridViewAdapter = new GridViewAdapter(getContext(), photos);
gridView.setAdapter(gridViewAdapter);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
我的GridViewAdapter.class,getView方法
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View gridView = convertView;
if(convertView == null){
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
gridView = inflater.inflate(R.layout.image_item,null);
}
ImageView imageView = gridView.findViewById(R.id.image_from_photo_album);
Picasso.with(context).load(photos.get(position)).into(imageView);
return imageView;
}
不带 Firebase 存储 URL 的 ScreenView:
带有 Firebase 存储 URL 的 ScreenView:
最佳答案
尝试将 Picasso.with(context).load(photos.get(position)).into(imageView)
更改为:
字符串 url = photos.get(position);
Picasso.with(context).load(url).into(imageView)
另外:也许您来自 Firebase 的照片网址始终为 Null,您调试过它吗?
关于java - 无法从 Firebase 下载照片 - 空白 ImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55716036/