Search code examples
androidfirebasefirebase-realtime-databasepicassoimagebutton

Set Image ImageButton Using Picasso


I need to set an image of an ImageButton to an image stored in Firebase.

I'm currently viewing the data in an EditText in this template:

nameCompanyDB = FirebaseDatabase.getInstance().getReference().child("Company").child(user_id).child("name_company");

mNameCompany = (EditText) findViewById(R.id.edtNameCompany);


nameCompanyDB.addListenerForSingleValueEvent(new ValueEventListener() {

            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                mNameCompany.setText(dataSnapshot.getValue(String.class));
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });

How could I do to display a stored image. I have the following bank details:

fotoCompanyDB = FirebaseDatabase.getInstance().getReference().child("Company").child(user_id).child("photo");

fotoCompanyDB.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {

        /* Set the image here */  
        /* I would like to use Picasso */              


            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });

Structure Picasso:
Class Example:
public void setImage(final Context c, final String image){

            final ImageView post_image = (ImageView) mView.findViewById(R.id.post_image);

            /*Procedimento preparado para funcionar offline*/
            Picasso.with(c).load(image).networkPolicy(NetworkPolicy.OFFLINE).into(post_image, new Callback() {
                @Override
                public void onSuccess() {

                }

                @Override
                public void onError() {

                    /*Processo para carregar e visualizar imagem - Ocorre quando estiver Online*/
                    Picasso.with(c).load(image).into(post_image);

                }
            });

        }
    }

Any way to use this structure template to display the FireBox result in the ImageButton?


Solution

  • I found the solution

    String urlFoto =  dataSnapshot.getValue(String.class);
    Picasso.with(this).load(urlFoto).into(mSelectImage);