How to wait for the image to load before the cycle “for” goes on in onDataChange + Glide?












0















I know that the onDataChange download is asynchronous, but the body has UI Thread. And loading images using Glide is also asynchronous. onDataChange is being executed, it comes to the body of the UI Thread, but there the image is loaded in the new thread and, therefore, the image does not have time to load, how the code is executed further.



myRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot ds : dataSnapshot.getChildren()) {
...
if(word.contains("https")){
Glide.with(Activity.this)
.load(url)
.into(imageView);
}else{
Log.d(TAG, "Another");
}
}
}
}


This is Firebase database.



How to wait for the image to load before the cycle "for" goes on?










share|improve this question

























  • Do you mean you need to load image first and then call onDataChange??

    – Rutvik Bhatt
    Nov 15 '18 at 7:47











  • You can store the value of dataSnapshot in a list, and perform image loading in a different method using the list of data which you call after the onDataChange task is completed.

    – ManishPrajapati
    Nov 15 '18 at 7:48






  • 3





    I don't understand what the problem is here.

    – Doug Stevenson
    Nov 15 '18 at 7:48











  • @RutvikBhatt No, at first, in onDataChange need to load image, then imageSend(imageView);

    – Inna Ahtina
    Nov 15 '18 at 7:51











  • Which version of Glide do you use?

    – Rutvik Bhatt
    Nov 15 '18 at 7:53
















0















I know that the onDataChange download is asynchronous, but the body has UI Thread. And loading images using Glide is also asynchronous. onDataChange is being executed, it comes to the body of the UI Thread, but there the image is loaded in the new thread and, therefore, the image does not have time to load, how the code is executed further.



myRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot ds : dataSnapshot.getChildren()) {
...
if(word.contains("https")){
Glide.with(Activity.this)
.load(url)
.into(imageView);
}else{
Log.d(TAG, "Another");
}
}
}
}


This is Firebase database.



How to wait for the image to load before the cycle "for" goes on?










share|improve this question

























  • Do you mean you need to load image first and then call onDataChange??

    – Rutvik Bhatt
    Nov 15 '18 at 7:47











  • You can store the value of dataSnapshot in a list, and perform image loading in a different method using the list of data which you call after the onDataChange task is completed.

    – ManishPrajapati
    Nov 15 '18 at 7:48






  • 3





    I don't understand what the problem is here.

    – Doug Stevenson
    Nov 15 '18 at 7:48











  • @RutvikBhatt No, at first, in onDataChange need to load image, then imageSend(imageView);

    – Inna Ahtina
    Nov 15 '18 at 7:51











  • Which version of Glide do you use?

    – Rutvik Bhatt
    Nov 15 '18 at 7:53














0












0








0








I know that the onDataChange download is asynchronous, but the body has UI Thread. And loading images using Glide is also asynchronous. onDataChange is being executed, it comes to the body of the UI Thread, but there the image is loaded in the new thread and, therefore, the image does not have time to load, how the code is executed further.



myRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot ds : dataSnapshot.getChildren()) {
...
if(word.contains("https")){
Glide.with(Activity.this)
.load(url)
.into(imageView);
}else{
Log.d(TAG, "Another");
}
}
}
}


This is Firebase database.



How to wait for the image to load before the cycle "for" goes on?










share|improve this question
















I know that the onDataChange download is asynchronous, but the body has UI Thread. And loading images using Glide is also asynchronous. onDataChange is being executed, it comes to the body of the UI Thread, but there the image is loaded in the new thread and, therefore, the image does not have time to load, how the code is executed further.



myRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot ds : dataSnapshot.getChildren()) {
...
if(word.contains("https")){
Glide.with(Activity.this)
.load(url)
.into(imageView);
}else{
Log.d(TAG, "Another");
}
}
}
}


This is Firebase database.



How to wait for the image to load before the cycle "for" goes on?







java android firebase firebase-realtime-database android-glide






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 9:40







Inna Ahtina

















asked Nov 15 '18 at 7:44









Inna AhtinaInna Ahtina

13




13













  • Do you mean you need to load image first and then call onDataChange??

    – Rutvik Bhatt
    Nov 15 '18 at 7:47











  • You can store the value of dataSnapshot in a list, and perform image loading in a different method using the list of data which you call after the onDataChange task is completed.

    – ManishPrajapati
    Nov 15 '18 at 7:48






  • 3





    I don't understand what the problem is here.

    – Doug Stevenson
    Nov 15 '18 at 7:48











  • @RutvikBhatt No, at first, in onDataChange need to load image, then imageSend(imageView);

    – Inna Ahtina
    Nov 15 '18 at 7:51











  • Which version of Glide do you use?

    – Rutvik Bhatt
    Nov 15 '18 at 7:53



















  • Do you mean you need to load image first and then call onDataChange??

    – Rutvik Bhatt
    Nov 15 '18 at 7:47











  • You can store the value of dataSnapshot in a list, and perform image loading in a different method using the list of data which you call after the onDataChange task is completed.

    – ManishPrajapati
    Nov 15 '18 at 7:48






  • 3





    I don't understand what the problem is here.

    – Doug Stevenson
    Nov 15 '18 at 7:48











  • @RutvikBhatt No, at first, in onDataChange need to load image, then imageSend(imageView);

    – Inna Ahtina
    Nov 15 '18 at 7:51











  • Which version of Glide do you use?

    – Rutvik Bhatt
    Nov 15 '18 at 7:53

















Do you mean you need to load image first and then call onDataChange??

– Rutvik Bhatt
Nov 15 '18 at 7:47





Do you mean you need to load image first and then call onDataChange??

– Rutvik Bhatt
Nov 15 '18 at 7:47













You can store the value of dataSnapshot in a list, and perform image loading in a different method using the list of data which you call after the onDataChange task is completed.

– ManishPrajapati
Nov 15 '18 at 7:48





You can store the value of dataSnapshot in a list, and perform image loading in a different method using the list of data which you call after the onDataChange task is completed.

– ManishPrajapati
Nov 15 '18 at 7:48




3




3





I don't understand what the problem is here.

– Doug Stevenson
Nov 15 '18 at 7:48





I don't understand what the problem is here.

– Doug Stevenson
Nov 15 '18 at 7:48













@RutvikBhatt No, at first, in onDataChange need to load image, then imageSend(imageView);

– Inna Ahtina
Nov 15 '18 at 7:51





@RutvikBhatt No, at first, in onDataChange need to load image, then imageSend(imageView);

– Inna Ahtina
Nov 15 '18 at 7:51













Which version of Glide do you use?

– Rutvik Bhatt
Nov 15 '18 at 7:53





Which version of Glide do you use?

– Rutvik Bhatt
Nov 15 '18 at 7:53












3 Answers
3






active

oldest

votes


















0














Put the Glide logic in a method passing dataSnapshot as param. Something like this :



Glide.with(Activity.this)
.load(url)
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
return false;
}

@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
imageSend(imageView);
return false;
}
})
.into(imageView);





share|improve this answer
























  • I updated the code, I need to prevent the execution situation from "else" while loading the image in "if"

    – Inna Ahtina
    Nov 15 '18 at 8:03











  • put this logic in a private method in your class, and call it when if condition is true

    – Ionut J. Bejan
    Nov 15 '18 at 8:04











  • Due to the fact that Glide is asynchronous, the code is executed further, without waiting for the download.

    – Inna Ahtina
    Nov 15 '18 at 8:14











  • If you put the code like this, it won't execute further (imageSend won't get called unless onResourceReady has been triggered). Also, there is nothing to be executed further.. I don't see your point here

    – Ionut J. Bejan
    Nov 15 '18 at 8:16











  • Thank you for your efforts to help, I will mark your question as correct and will re-create the question with great details. Tell me, is it possible in this case to create a new question or is it better to edit this one?

    – Inna Ahtina
    Nov 15 '18 at 8:25



















0














If you are using Glide-v4, you can set a listener for loading the image like this:



Glide.with(Activity.this)
.load(url)
.listener(new RequestListener<Drawable>() {

@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
return false;
}

@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
imageSend(imageView);
return false;
}
})
.into(imageView);





share|improve this answer
























  • Updated the question and code now. I would be grateful for the help in the question. I think now the question is asked correctly.

    – Inna Ahtina
    Nov 15 '18 at 9:32



















0














Try this,



Declare a global variable:



ArrayList<String> list = new ArrayList<>();


add urls to list:



myRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot childDS : dataSnapshot.getChildren()){
list.add(childDS.getValue(String.class));
}
setImages(list); // this function will be called only after all the URLs are added to the list
}
}


Create a new method:



void setImages(ArrayList<String> urlList){
for(int i = 0; i<urlList.size; i++){
if(urlList.get(i).contains("https")){
Glide.with(Activity.this)
.load(url)
.into(imageView);
imageSend(imageView);
}else{
Log.d(TAG, "Another");
}
}
}





share|improve this answer
























  • Updated the question and code now. I would be grateful for the help in the question.

    – Inna Ahtina
    Nov 15 '18 at 9:31











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%2f53314573%2fhow-to-wait-for-the-image-to-load-before-the-cycle-for-goes-on-in-ondatachange%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Put the Glide logic in a method passing dataSnapshot as param. Something like this :



Glide.with(Activity.this)
.load(url)
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
return false;
}

@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
imageSend(imageView);
return false;
}
})
.into(imageView);





share|improve this answer
























  • I updated the code, I need to prevent the execution situation from "else" while loading the image in "if"

    – Inna Ahtina
    Nov 15 '18 at 8:03











  • put this logic in a private method in your class, and call it when if condition is true

    – Ionut J. Bejan
    Nov 15 '18 at 8:04











  • Due to the fact that Glide is asynchronous, the code is executed further, without waiting for the download.

    – Inna Ahtina
    Nov 15 '18 at 8:14











  • If you put the code like this, it won't execute further (imageSend won't get called unless onResourceReady has been triggered). Also, there is nothing to be executed further.. I don't see your point here

    – Ionut J. Bejan
    Nov 15 '18 at 8:16











  • Thank you for your efforts to help, I will mark your question as correct and will re-create the question with great details. Tell me, is it possible in this case to create a new question or is it better to edit this one?

    – Inna Ahtina
    Nov 15 '18 at 8:25
















0














Put the Glide logic in a method passing dataSnapshot as param. Something like this :



Glide.with(Activity.this)
.load(url)
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
return false;
}

@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
imageSend(imageView);
return false;
}
})
.into(imageView);





share|improve this answer
























  • I updated the code, I need to prevent the execution situation from "else" while loading the image in "if"

    – Inna Ahtina
    Nov 15 '18 at 8:03











  • put this logic in a private method in your class, and call it when if condition is true

    – Ionut J. Bejan
    Nov 15 '18 at 8:04











  • Due to the fact that Glide is asynchronous, the code is executed further, without waiting for the download.

    – Inna Ahtina
    Nov 15 '18 at 8:14











  • If you put the code like this, it won't execute further (imageSend won't get called unless onResourceReady has been triggered). Also, there is nothing to be executed further.. I don't see your point here

    – Ionut J. Bejan
    Nov 15 '18 at 8:16











  • Thank you for your efforts to help, I will mark your question as correct and will re-create the question with great details. Tell me, is it possible in this case to create a new question or is it better to edit this one?

    – Inna Ahtina
    Nov 15 '18 at 8:25














0












0








0







Put the Glide logic in a method passing dataSnapshot as param. Something like this :



Glide.with(Activity.this)
.load(url)
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
return false;
}

@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
imageSend(imageView);
return false;
}
})
.into(imageView);





share|improve this answer













Put the Glide logic in a method passing dataSnapshot as param. Something like this :



Glide.with(Activity.this)
.load(url)
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
return false;
}

@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
imageSend(imageView);
return false;
}
})
.into(imageView);






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 7:55









Ionut J. BejanIonut J. Bejan

436516




436516













  • I updated the code, I need to prevent the execution situation from "else" while loading the image in "if"

    – Inna Ahtina
    Nov 15 '18 at 8:03











  • put this logic in a private method in your class, and call it when if condition is true

    – Ionut J. Bejan
    Nov 15 '18 at 8:04











  • Due to the fact that Glide is asynchronous, the code is executed further, without waiting for the download.

    – Inna Ahtina
    Nov 15 '18 at 8:14











  • If you put the code like this, it won't execute further (imageSend won't get called unless onResourceReady has been triggered). Also, there is nothing to be executed further.. I don't see your point here

    – Ionut J. Bejan
    Nov 15 '18 at 8:16











  • Thank you for your efforts to help, I will mark your question as correct and will re-create the question with great details. Tell me, is it possible in this case to create a new question or is it better to edit this one?

    – Inna Ahtina
    Nov 15 '18 at 8:25



















  • I updated the code, I need to prevent the execution situation from "else" while loading the image in "if"

    – Inna Ahtina
    Nov 15 '18 at 8:03











  • put this logic in a private method in your class, and call it when if condition is true

    – Ionut J. Bejan
    Nov 15 '18 at 8:04











  • Due to the fact that Glide is asynchronous, the code is executed further, without waiting for the download.

    – Inna Ahtina
    Nov 15 '18 at 8:14











  • If you put the code like this, it won't execute further (imageSend won't get called unless onResourceReady has been triggered). Also, there is nothing to be executed further.. I don't see your point here

    – Ionut J. Bejan
    Nov 15 '18 at 8:16











  • Thank you for your efforts to help, I will mark your question as correct and will re-create the question with great details. Tell me, is it possible in this case to create a new question or is it better to edit this one?

    – Inna Ahtina
    Nov 15 '18 at 8:25

















I updated the code, I need to prevent the execution situation from "else" while loading the image in "if"

– Inna Ahtina
Nov 15 '18 at 8:03





I updated the code, I need to prevent the execution situation from "else" while loading the image in "if"

– Inna Ahtina
Nov 15 '18 at 8:03













put this logic in a private method in your class, and call it when if condition is true

– Ionut J. Bejan
Nov 15 '18 at 8:04





put this logic in a private method in your class, and call it when if condition is true

– Ionut J. Bejan
Nov 15 '18 at 8:04













Due to the fact that Glide is asynchronous, the code is executed further, without waiting for the download.

– Inna Ahtina
Nov 15 '18 at 8:14





Due to the fact that Glide is asynchronous, the code is executed further, without waiting for the download.

– Inna Ahtina
Nov 15 '18 at 8:14













If you put the code like this, it won't execute further (imageSend won't get called unless onResourceReady has been triggered). Also, there is nothing to be executed further.. I don't see your point here

– Ionut J. Bejan
Nov 15 '18 at 8:16





If you put the code like this, it won't execute further (imageSend won't get called unless onResourceReady has been triggered). Also, there is nothing to be executed further.. I don't see your point here

– Ionut J. Bejan
Nov 15 '18 at 8:16













Thank you for your efforts to help, I will mark your question as correct and will re-create the question with great details. Tell me, is it possible in this case to create a new question or is it better to edit this one?

– Inna Ahtina
Nov 15 '18 at 8:25





Thank you for your efforts to help, I will mark your question as correct and will re-create the question with great details. Tell me, is it possible in this case to create a new question or is it better to edit this one?

– Inna Ahtina
Nov 15 '18 at 8:25













0














If you are using Glide-v4, you can set a listener for loading the image like this:



Glide.with(Activity.this)
.load(url)
.listener(new RequestListener<Drawable>() {

@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
return false;
}

@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
imageSend(imageView);
return false;
}
})
.into(imageView);





share|improve this answer
























  • Updated the question and code now. I would be grateful for the help in the question. I think now the question is asked correctly.

    – Inna Ahtina
    Nov 15 '18 at 9:32
















0














If you are using Glide-v4, you can set a listener for loading the image like this:



Glide.with(Activity.this)
.load(url)
.listener(new RequestListener<Drawable>() {

@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
return false;
}

@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
imageSend(imageView);
return false;
}
})
.into(imageView);





share|improve this answer
























  • Updated the question and code now. I would be grateful for the help in the question. I think now the question is asked correctly.

    – Inna Ahtina
    Nov 15 '18 at 9:32














0












0








0







If you are using Glide-v4, you can set a listener for loading the image like this:



Glide.with(Activity.this)
.load(url)
.listener(new RequestListener<Drawable>() {

@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
return false;
}

@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
imageSend(imageView);
return false;
}
})
.into(imageView);





share|improve this answer













If you are using Glide-v4, you can set a listener for loading the image like this:



Glide.with(Activity.this)
.load(url)
.listener(new RequestListener<Drawable>() {

@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
return false;
}

@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
imageSend(imageView);
return false;
}
})
.into(imageView);






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 7:56









aminographyaminography

5,97521231




5,97521231













  • Updated the question and code now. I would be grateful for the help in the question. I think now the question is asked correctly.

    – Inna Ahtina
    Nov 15 '18 at 9:32



















  • Updated the question and code now. I would be grateful for the help in the question. I think now the question is asked correctly.

    – Inna Ahtina
    Nov 15 '18 at 9:32

















Updated the question and code now. I would be grateful for the help in the question. I think now the question is asked correctly.

– Inna Ahtina
Nov 15 '18 at 9:32





Updated the question and code now. I would be grateful for the help in the question. I think now the question is asked correctly.

– Inna Ahtina
Nov 15 '18 at 9:32











0














Try this,



Declare a global variable:



ArrayList<String> list = new ArrayList<>();


add urls to list:



myRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot childDS : dataSnapshot.getChildren()){
list.add(childDS.getValue(String.class));
}
setImages(list); // this function will be called only after all the URLs are added to the list
}
}


Create a new method:



void setImages(ArrayList<String> urlList){
for(int i = 0; i<urlList.size; i++){
if(urlList.get(i).contains("https")){
Glide.with(Activity.this)
.load(url)
.into(imageView);
imageSend(imageView);
}else{
Log.d(TAG, "Another");
}
}
}





share|improve this answer
























  • Updated the question and code now. I would be grateful for the help in the question.

    – Inna Ahtina
    Nov 15 '18 at 9:31
















0














Try this,



Declare a global variable:



ArrayList<String> list = new ArrayList<>();


add urls to list:



myRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot childDS : dataSnapshot.getChildren()){
list.add(childDS.getValue(String.class));
}
setImages(list); // this function will be called only after all the URLs are added to the list
}
}


Create a new method:



void setImages(ArrayList<String> urlList){
for(int i = 0; i<urlList.size; i++){
if(urlList.get(i).contains("https")){
Glide.with(Activity.this)
.load(url)
.into(imageView);
imageSend(imageView);
}else{
Log.d(TAG, "Another");
}
}
}





share|improve this answer
























  • Updated the question and code now. I would be grateful for the help in the question.

    – Inna Ahtina
    Nov 15 '18 at 9:31














0












0








0







Try this,



Declare a global variable:



ArrayList<String> list = new ArrayList<>();


add urls to list:



myRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot childDS : dataSnapshot.getChildren()){
list.add(childDS.getValue(String.class));
}
setImages(list); // this function will be called only after all the URLs are added to the list
}
}


Create a new method:



void setImages(ArrayList<String> urlList){
for(int i = 0; i<urlList.size; i++){
if(urlList.get(i).contains("https")){
Glide.with(Activity.this)
.load(url)
.into(imageView);
imageSend(imageView);
}else{
Log.d(TAG, "Another");
}
}
}





share|improve this answer













Try this,



Declare a global variable:



ArrayList<String> list = new ArrayList<>();


add urls to list:



myRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot childDS : dataSnapshot.getChildren()){
list.add(childDS.getValue(String.class));
}
setImages(list); // this function will be called only after all the URLs are added to the list
}
}


Create a new method:



void setImages(ArrayList<String> urlList){
for(int i = 0; i<urlList.size; i++){
if(urlList.get(i).contains("https")){
Glide.with(Activity.this)
.load(url)
.into(imageView);
imageSend(imageView);
}else{
Log.d(TAG, "Another");
}
}
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 9:24









ManishPrajapatiManishPrajapati

221314




221314













  • Updated the question and code now. I would be grateful for the help in the question.

    – Inna Ahtina
    Nov 15 '18 at 9:31



















  • Updated the question and code now. I would be grateful for the help in the question.

    – Inna Ahtina
    Nov 15 '18 at 9:31

















Updated the question and code now. I would be grateful for the help in the question.

– Inna Ahtina
Nov 15 '18 at 9:31





Updated the question and code now. I would be grateful for the help in the question.

– Inna Ahtina
Nov 15 '18 at 9:31


















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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53314573%2fhow-to-wait-for-the-image-to-load-before-the-cycle-for-goes-on-in-ondatachange%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







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()