My recycler view is not showing any firebase images

前端 未结 1 1717
误落风尘
误落风尘 2020-12-04 03:47

I am trying to retrieve data from the database to a recyclerview but the only name of an image is showing in the recyclerview. The image is not getting load in image . Here

相关标签:
1条回答
  • 2020-12-04 04:35

    I will Assume that this is the database:

    Uploads
    |
    |---------someID
              |
              |----name:"...."
                   image:"..........."
    
    
    ---------someID
              |
              |----name:"...."
                   image:"..........."
    

    If your database is some thing like this in onBindViewHolder:

    FirebaseRecyclerAdapter<HealthTips, hViewHolder> adapter= new FirebaseRecyclerAdapter<HealthTips, hViewHolder>(options) {
     @Override
    protected void onBindViewHolder(@NonNull final hViewHolder holder, int i, @NonNull final HealthTips healthTips) {
    
    
    //directly get the values like this
    String Iname = healthTips.getName();
    String Uimage = healthTips.getImage();
    holder.hName.setText(Iname);
    Picasso.get().load(Uimage).into(holder.hImageview);
    
    
    }
    ...............
     ..............
    

    According to your database your HealthTips must be like this:

    public class HealthTips {
    
    private String name, imageUrl;
    
    public HealthTips(){
    
    
    }
    public HealthTips(String name, String imageUrl){
    
        this.name = name;
        this.imageUrl = imageUrl;
    
    }
    public String getName(){
        return name;
    }
    public void setName(String name){
        this.name = name;
    }
    public String getImageUrl(){
        return imageUrl;
    }
    public void setImageUrl(String imageUrl){
        this.imageUrl= imageUrl;
    }
    
    
    }
    

    UPDATE----------

    I think you are uploading the url wrong to database, maybe try this in onSuccess() of the uploadFile():

    ........
    ........
    Toast.makeText(Admin.this, "Upload Successful",Toast.LENGTH_SHORT).show();
    
    
    //get download url
    fileReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
    @Override
    public void onSuccess(Uri uri) {
    //this is the url to post to database
    Upload upload = new Upload(mEditTextFileName.getText().toString().trim(),uri.toString());
    
    //upload
    String uploadId = mDatabaseRef.push().getKey();
    mDatabaseRef.child(uploadId).setValue(upload);
    
    }
    
    ............
    ............
    
    0 讨论(0)
提交回复
热议问题