Skip to content Skip to sidebar Skip to footer

How To Populate A Gridview With Images Retreieved From Firebase Storage

I have reviewed other similar posts before posting this, mine is different I am current retrieving a list of download urls from my Firestore data base, then trying to download thos

Solution 1:

As I see in your screenshot, your document hols only a single image. So to solve this, there is no need for an extra inner for-loop. To create a list of those images, please use the following lines of code:

Query chatRoomMsgs = db.collection("chatrooms").document(chatRoomID)
    .collection("Messages").whereEqualTo("sentby", firebaseAuth.getUid());
chatRoomMsgs.get().addOnCompleteListener(newOnCompleteListener<QuerySnapshot>() {
    @OverridepublicvoidonComplete(@NonNull Task<QuerySnapshot> task) {
        if (task.isSuccessful()) {
            ArrayList<String> sentPicsURLS = newArrayList<>();
            for (QueryDocumentSnapshotdocument : task.getResult()) {
                sentPicsURLS.add(document.getString("image"));
            }
            //Do what you need to do with your listLog.d(TAG, "List size: " + sentPicsURLS.size());
        }
    }
});

Be also aware that Firebase APIs are asynchronous and you can use that list only inside the callback. Now, the result in your logcat will be size of your list.

Post a Comment for "How To Populate A Gridview With Images Retreieved From Firebase Storage"