Put Firebase link on each button of the app on Android

Asked

Viewed 278 times

-1

I need the image button to get the link to Firebase to download the image of the application. I will present my App to be clearer.

I have this app:

inserir a descrição da imagem aqui

I was able to use the text and image of Firebase Database and of Firebase Store. They are appearing correctly.

inserir a descrição da imagem aqui

I want each image to have its own download link through a Array using the Firebase Database. I need to put this link on each button of the array. Then each image will have its own download button link.

I don’t care if it’s in Textview or in Button. Follow the code below:

Class Mainactivity

public class MainActivity extends AppCompatActivity {

    private StorageReference mStorageReference;
    private RecyclerView mImageList;
    private DatabaseReference mDatabase;
    DownloadManager dm;
    long queueid;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mDatabase = FirebaseDatabase.getInstance().getReference().child("Image");

        mImageList = (RecyclerView) findViewById(R.id.image_list);
        mImageList.setHasFixedSize(true);
        mImageList.setLayoutManager(new LinearLayoutManager(this));
    }

@Override
protected  void onStart(){
    super.onStart();

    FirebaseRecyclerAdapter<Image, ImageViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Image, ImageViewHolder>(
            Image.class,
            R.layout.image_row,
            ImageViewHolder.class,
            mDatabase
    ){
        @Override
        protected void populateViewHolder (ImageViewHolder viewHolder, Image model,int position)
        {
            viewHolder.setTitle(model.getTitle());
            viewHolder.setImage(getApplicationContext(),model.getImage());
        }
    };
    mImageList.setAdapter(firebaseRecyclerAdapter);
}

    public static class ImageViewHolder extends RecyclerView.ViewHolder{
        View mView;


        //constructor
        public ImageViewHolder(View itemView) {
            super(itemView);

            mView = itemView;
        }

        public void setTitle(String title){
            TextView post_title = (TextView) mView.findViewById(R.id.post_title);
            post_title.setText(title);
        }

        public void setImage(Context ctx, String image){
            ImageView post_image = (ImageView) mView.findViewById(R.id.post_image);
           /* Glide.with(ctx)
                    .load(image)
                    .into(post_image);*/
            Picasso.with(ctx).load(image).into(post_image);
        }

    }

}

Class Image

public class Image {

    private String title;
    private String download;
    private String image;
    DownloadManager dm;

    public Image(){

    }

    public Image(String title, String download, String image){
        this.title = title;
        this.download = download;
        this.image = image;
    }

    public String getTitle() {
        return title;
    }

    public String getDownload() {
        return download;
    }

    public String getImage() {
        return image;
    }

    public void setImage(String image){
        this.image = image;
    }
}

1 answer

1


Puts in:

  @Override
        protected void populateViewHolder (ImageViewHolder viewHolder, Image model,int position)
        {
            viewHolder.setTitle(model.getTitle());
            viewHolder.setImage(getApplicationContext(),model.getImage());
            viewHolder.setDownload(getAplicationContext(), model.getDownload());

        }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.