我想开发一个应用程序,它将字符串转换为我已经做过的单词数组。但问题是当我使用for循环和Firebase查询通过thread.sleep(5000)一个接一个地显示来自firebase存储的图像时;它不起作用。它总是只显示最后一个单词的图像和最后一个单词。
这是我的代码:
String str=matches.get(0).toLowerCase();
final String[] word=str.split(" ");
//speexhTxt.setText(word.length);
// speexhTxt.setText(String.valueOf(one));
for (i=0;i<word.length;i++) {
progressBar.setVisibility(View.VISIBLE);
imageHide.setVisibility(View.GONE);
signImage.setVisibility(View.VISIBLE);
firebaseFirestore= FirebaseFirestore.getInstance();
collectionReference=firebaseFirestore.collection("dumbsign");
Query query=collectionReference.whereEqualTo("word",word[i]);
final int finalI = i;
query.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()){
for (QueryDocumentSnapshot doc : task.getResult()){
Glide.with(getApplicationContext()).
load(doc.getString("image_url"))
.into(signImage);
speexhTxt.setText(word[finalI]);
progressBar.setVisibility(View.GONE);
}
};
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
}