How to populate listview with images from Firebase Database in android?












1














I have stored links to the images in my Firebase storage to my Firebase Database. The JSON structure for my database is something like this:



|
--- users
|
|
---- uid1
| |
| -- uid1
| |
| -- name
| |
| -- imageURL
| |
|
|
-- uid2


What I want to do is populate my listview with images from this. I also need to know how to populate listview with images.



I read some answers on stack overflow but I couldn't understand how should I start with this.



I would appreciate if someone could provide information and some code to start with this.



EDIT:
I am able to get the imageURL from the database, I was not stuck in that. I want to know how can I populate listview with images? I saw some answers on StackOverflow but none of them could properly address my problem.










share|improve this question
























  • If you are using recyclerview, you can fetch the list of data from firebase and get the image in Adapter using picasso.
    – ManishPrajapati
    Nov 10 at 14:53
















1














I have stored links to the images in my Firebase storage to my Firebase Database. The JSON structure for my database is something like this:



|
--- users
|
|
---- uid1
| |
| -- uid1
| |
| -- name
| |
| -- imageURL
| |
|
|
-- uid2


What I want to do is populate my listview with images from this. I also need to know how to populate listview with images.



I read some answers on stack overflow but I couldn't understand how should I start with this.



I would appreciate if someone could provide information and some code to start with this.



EDIT:
I am able to get the imageURL from the database, I was not stuck in that. I want to know how can I populate listview with images? I saw some answers on StackOverflow but none of them could properly address my problem.










share|improve this question
























  • If you are using recyclerview, you can fetch the list of data from firebase and get the image in Adapter using picasso.
    – ManishPrajapati
    Nov 10 at 14:53














1












1








1







I have stored links to the images in my Firebase storage to my Firebase Database. The JSON structure for my database is something like this:



|
--- users
|
|
---- uid1
| |
| -- uid1
| |
| -- name
| |
| -- imageURL
| |
|
|
-- uid2


What I want to do is populate my listview with images from this. I also need to know how to populate listview with images.



I read some answers on stack overflow but I couldn't understand how should I start with this.



I would appreciate if someone could provide information and some code to start with this.



EDIT:
I am able to get the imageURL from the database, I was not stuck in that. I want to know how can I populate listview with images? I saw some answers on StackOverflow but none of them could properly address my problem.










share|improve this question















I have stored links to the images in my Firebase storage to my Firebase Database. The JSON structure for my database is something like this:



|
--- users
|
|
---- uid1
| |
| -- uid1
| |
| -- name
| |
| -- imageURL
| |
|
|
-- uid2


What I want to do is populate my listview with images from this. I also need to know how to populate listview with images.



I read some answers on stack overflow but I couldn't understand how should I start with this.



I would appreciate if someone could provide information and some code to start with this.



EDIT:
I am able to get the imageURL from the database, I was not stuck in that. I want to know how can I populate listview with images? I saw some answers on StackOverflow but none of them could properly address my problem.







java android firebase firebase-realtime-database firebase-storage






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 5:17

























asked Nov 10 at 14:30









Manhar

95113




95113












  • If you are using recyclerview, you can fetch the list of data from firebase and get the image in Adapter using picasso.
    – ManishPrajapati
    Nov 10 at 14:53


















  • If you are using recyclerview, you can fetch the list of data from firebase and get the image in Adapter using picasso.
    – ManishPrajapati
    Nov 10 at 14:53
















If you are using recyclerview, you can fetch the list of data from firebase and get the image in Adapter using picasso.
– ManishPrajapati
Nov 10 at 14:53




If you are using recyclerview, you can fetch the list of data from firebase and get the image in Adapter using picasso.
– ManishPrajapati
Nov 10 at 14:53












2 Answers
2






active

oldest

votes


















1














This can be done by fetching the image url from Firebase in your adapter or wherever you want to set your image. A sample code assuming you have a list of images to use:



FirebaseDatabase.getInstance().getReference().child("users").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot ds:dataSnapshot.getChildren()){
String image = ds.child("image").getValue(String.class);
// You can now set your Image with any method you want, Glide Picasso or any other library
// GlideApp.with(getContext())
// .load(image)
// .placeholder(new ColorDrawable(getResources().getColor(R.color.colorWhite)))// you can use any color here
// .fitCenter()
// .into(image_view);// An ImageView instance
}
}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {

}
});


What is being done here, should be where you fetch your items to be displayed in the ListView. After obtaining the list, you can then pass them into your adapter. The commented GlideApp call is supposed to happen in the getView method of your adapter






share|improve this answer























  • Thank you for your answer, can you tell how can I populate listview with images from this? Do I have to put imageviews inside the listview, but there are dynamic number of users and hence I can't just put a fixed number of image views
    – Manhar
    Nov 10 at 15:31










  • Can you post more details about how you are already implementing your list view updates?
    – Cool Guy CG
    Nov 10 at 15:55










  • Can you tell how can I do that. I edited the question. I would provide the code, but I am not getting how can I implement this. I have just a listview and I am trying to find out the way to populate it with images.
    – Manhar
    Nov 11 at 5:21



















0














If you can use the retrofit to fetch the images from Firebase, then it would be very easy to populate the images into RecyclerView. If you are not aware of the retrofit, you can follow this great tutorial. https://www.raywenderlich.com/4539-android-networking






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239941%2fhow-to-populate-listview-with-images-from-firebase-database-in-android%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    This can be done by fetching the image url from Firebase in your adapter or wherever you want to set your image. A sample code assuming you have a list of images to use:



    FirebaseDatabase.getInstance().getReference().child("users").addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
    for(DataSnapshot ds:dataSnapshot.getChildren()){
    String image = ds.child("image").getValue(String.class);
    // You can now set your Image with any method you want, Glide Picasso or any other library
    // GlideApp.with(getContext())
    // .load(image)
    // .placeholder(new ColorDrawable(getResources().getColor(R.color.colorWhite)))// you can use any color here
    // .fitCenter()
    // .into(image_view);// An ImageView instance
    }
    }

    @Override
    public void onCancelled(@NonNull DatabaseError databaseError) {

    }
    });


    What is being done here, should be where you fetch your items to be displayed in the ListView. After obtaining the list, you can then pass them into your adapter. The commented GlideApp call is supposed to happen in the getView method of your adapter






    share|improve this answer























    • Thank you for your answer, can you tell how can I populate listview with images from this? Do I have to put imageviews inside the listview, but there are dynamic number of users and hence I can't just put a fixed number of image views
      – Manhar
      Nov 10 at 15:31










    • Can you post more details about how you are already implementing your list view updates?
      – Cool Guy CG
      Nov 10 at 15:55










    • Can you tell how can I do that. I edited the question. I would provide the code, but I am not getting how can I implement this. I have just a listview and I am trying to find out the way to populate it with images.
      – Manhar
      Nov 11 at 5:21
















    1














    This can be done by fetching the image url from Firebase in your adapter or wherever you want to set your image. A sample code assuming you have a list of images to use:



    FirebaseDatabase.getInstance().getReference().child("users").addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
    for(DataSnapshot ds:dataSnapshot.getChildren()){
    String image = ds.child("image").getValue(String.class);
    // You can now set your Image with any method you want, Glide Picasso or any other library
    // GlideApp.with(getContext())
    // .load(image)
    // .placeholder(new ColorDrawable(getResources().getColor(R.color.colorWhite)))// you can use any color here
    // .fitCenter()
    // .into(image_view);// An ImageView instance
    }
    }

    @Override
    public void onCancelled(@NonNull DatabaseError databaseError) {

    }
    });


    What is being done here, should be where you fetch your items to be displayed in the ListView. After obtaining the list, you can then pass them into your adapter. The commented GlideApp call is supposed to happen in the getView method of your adapter






    share|improve this answer























    • Thank you for your answer, can you tell how can I populate listview with images from this? Do I have to put imageviews inside the listview, but there are dynamic number of users and hence I can't just put a fixed number of image views
      – Manhar
      Nov 10 at 15:31










    • Can you post more details about how you are already implementing your list view updates?
      – Cool Guy CG
      Nov 10 at 15:55










    • Can you tell how can I do that. I edited the question. I would provide the code, but I am not getting how can I implement this. I have just a listview and I am trying to find out the way to populate it with images.
      – Manhar
      Nov 11 at 5:21














    1












    1








    1






    This can be done by fetching the image url from Firebase in your adapter or wherever you want to set your image. A sample code assuming you have a list of images to use:



    FirebaseDatabase.getInstance().getReference().child("users").addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
    for(DataSnapshot ds:dataSnapshot.getChildren()){
    String image = ds.child("image").getValue(String.class);
    // You can now set your Image with any method you want, Glide Picasso or any other library
    // GlideApp.with(getContext())
    // .load(image)
    // .placeholder(new ColorDrawable(getResources().getColor(R.color.colorWhite)))// you can use any color here
    // .fitCenter()
    // .into(image_view);// An ImageView instance
    }
    }

    @Override
    public void onCancelled(@NonNull DatabaseError databaseError) {

    }
    });


    What is being done here, should be where you fetch your items to be displayed in the ListView. After obtaining the list, you can then pass them into your adapter. The commented GlideApp call is supposed to happen in the getView method of your adapter






    share|improve this answer














    This can be done by fetching the image url from Firebase in your adapter or wherever you want to set your image. A sample code assuming you have a list of images to use:



    FirebaseDatabase.getInstance().getReference().child("users").addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
    for(DataSnapshot ds:dataSnapshot.getChildren()){
    String image = ds.child("image").getValue(String.class);
    // You can now set your Image with any method you want, Glide Picasso or any other library
    // GlideApp.with(getContext())
    // .load(image)
    // .placeholder(new ColorDrawable(getResources().getColor(R.color.colorWhite)))// you can use any color here
    // .fitCenter()
    // .into(image_view);// An ImageView instance
    }
    }

    @Override
    public void onCancelled(@NonNull DatabaseError databaseError) {

    }
    });


    What is being done here, should be where you fetch your items to be displayed in the ListView. After obtaining the list, you can then pass them into your adapter. The commented GlideApp call is supposed to happen in the getView method of your adapter







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 10 at 15:54

























    answered Nov 10 at 15:15









    Cool Guy CG

    71048




    71048












    • Thank you for your answer, can you tell how can I populate listview with images from this? Do I have to put imageviews inside the listview, but there are dynamic number of users and hence I can't just put a fixed number of image views
      – Manhar
      Nov 10 at 15:31










    • Can you post more details about how you are already implementing your list view updates?
      – Cool Guy CG
      Nov 10 at 15:55










    • Can you tell how can I do that. I edited the question. I would provide the code, but I am not getting how can I implement this. I have just a listview and I am trying to find out the way to populate it with images.
      – Manhar
      Nov 11 at 5:21


















    • Thank you for your answer, can you tell how can I populate listview with images from this? Do I have to put imageviews inside the listview, but there are dynamic number of users and hence I can't just put a fixed number of image views
      – Manhar
      Nov 10 at 15:31










    • Can you post more details about how you are already implementing your list view updates?
      – Cool Guy CG
      Nov 10 at 15:55










    • Can you tell how can I do that. I edited the question. I would provide the code, but I am not getting how can I implement this. I have just a listview and I am trying to find out the way to populate it with images.
      – Manhar
      Nov 11 at 5:21
















    Thank you for your answer, can you tell how can I populate listview with images from this? Do I have to put imageviews inside the listview, but there are dynamic number of users and hence I can't just put a fixed number of image views
    – Manhar
    Nov 10 at 15:31




    Thank you for your answer, can you tell how can I populate listview with images from this? Do I have to put imageviews inside the listview, but there are dynamic number of users and hence I can't just put a fixed number of image views
    – Manhar
    Nov 10 at 15:31












    Can you post more details about how you are already implementing your list view updates?
    – Cool Guy CG
    Nov 10 at 15:55




    Can you post more details about how you are already implementing your list view updates?
    – Cool Guy CG
    Nov 10 at 15:55












    Can you tell how can I do that. I edited the question. I would provide the code, but I am not getting how can I implement this. I have just a listview and I am trying to find out the way to populate it with images.
    – Manhar
    Nov 11 at 5:21




    Can you tell how can I do that. I edited the question. I would provide the code, but I am not getting how can I implement this. I have just a listview and I am trying to find out the way to populate it with images.
    – Manhar
    Nov 11 at 5:21













    0














    If you can use the retrofit to fetch the images from Firebase, then it would be very easy to populate the images into RecyclerView. If you are not aware of the retrofit, you can follow this great tutorial. https://www.raywenderlich.com/4539-android-networking






    share|improve this answer


























      0














      If you can use the retrofit to fetch the images from Firebase, then it would be very easy to populate the images into RecyclerView. If you are not aware of the retrofit, you can follow this great tutorial. https://www.raywenderlich.com/4539-android-networking






      share|improve this answer
























        0












        0








        0






        If you can use the retrofit to fetch the images from Firebase, then it would be very easy to populate the images into RecyclerView. If you are not aware of the retrofit, you can follow this great tutorial. https://www.raywenderlich.com/4539-android-networking






        share|improve this answer












        If you can use the retrofit to fetch the images from Firebase, then it would be very easy to populate the images into RecyclerView. If you are not aware of the retrofit, you can follow this great tutorial. https://www.raywenderlich.com/4539-android-networking







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 16:19









        hemandroid

        317




        317






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239941%2fhow-to-populate-listview-with-images-from-firebase-database-in-android%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Schultheiß

            Liste der Kulturdenkmale in Wilsdruff

            Android Play Services Check