为什么我从firebase检索到的图像在recyclerview中不显示/不可见?

时间:2019-04-24 03:43:07

标签: android android-glide

我想将图像上传到Firebase存储和Firebase实时数据库,并在recyclerview中查看它。该图像还包含文本,用户可以在其中指定其图像标题。尝试在recyclerview中显示上载的图像时,仅可见文本,但不显示图像。以下是我的recyclerview适配器:-firebase realtime database storing the image url and name

`package com.example.fieldhockeybooking;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;


public class RecycleViewAdapter extends RecyclerView.Adapter<RecycleViewAdapter.ViewHolder> {

    Context context;
    List<AdvertUploadInfo> MainImageUploadInfoList;

    public RecycleViewAdapter(Context context, List<AdvertUploadInfo> TempList) {

        this.MainImageUploadInfoList = TempList;

        this.context = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recyclerview_items, parent, false);

        ViewHolder viewHolder = new ViewHolder(view);

        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        AdvertUploadInfo UploadInfo = MainImageUploadInfoList.get(position);

        holder.imageNameTextView.setText(UploadInfo.getImageName());

        //Loading image from Glide library.
        Glide.with(context)
                .load(UploadInfo.getImageURL())
                .into(holder.imageView);
    }

    @Override
    public int getItemCount() {

        return MainImageUploadInfoList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        public ImageView imageView;
        public TextView imageNameTextView;

        public ViewHolder(View itemView) {
            super(itemView);

            imageView = (ImageView) itemView.findViewById(R.id.imageView);

            imageNameTextView = (TextView) itemView.findViewById(R.id.ImageNameTextView);
        }
    }
}
`

this is what shown from my android apps when i try to show all uploaded images

2 个答案:

答案 0 :(得分:0)

您必须使用match /{allPaths=**}设置安全规则,以表明在所有路径上都允许公共读写访问:

service firebase.storage {
  match /b/savephoto-a1cc3.appspot.com/o {
    match /{allPaths=**} {
      // Allow access by all users
      allow read, write;
    }
  }
}

答案 1 :(得分:0)

您必须在firebase实时数据库中设置规则以检索图像并在recyclerview中显示。 检查此链接 https://firebase.google.com/docs/database/security/