我想循环遍历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!");
}
});
}