如何在for循环中查询Firebase存储?

时间:2016-11-21 01:06:10

标签: android multithreading firebase firebase-realtime-database firebase-storage

我想循环遍历Arraylist我称为CardModel的个人对象。对于每个cardModel,我想转到Firebase存储并抓取该cardModel对象的相应图像。问题是,我在Firebase存储查询之前完成了for循环,因此它错误地添加了图像。我希望有人可以帮我解决这个问题。

        private int q = 1;
        for(CardModel cardModel : localCardArray)
        {
            imageStorage = storageRef.child("reference to firebase storage");
            imageStorage.getBytes(ONE_MEGABYTE).addOnSuccessListener(new OnSuccessListener<byte[]>() {
                @Override
                public void onSuccess(byte[] bytes)
                {
                    localByteArray.add(bytes);

                   //Once you're at the end of the arraylist, run next method
                    if(q++ == localCardArray.size())
                    {
                        setAdapter();
                    }
                }
            }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception exception) {
                    // Handle any errors
                    Log.d("testingImageInMain", "failure!");
                }
            });
        }

0 个答案:

没有答案