Java 如何以排序方式检索文档的值?

Java 如何以排序方式检索文档的值?,java,android,firebase,google-cloud-firestore,Java,Android,Firebase,Google Cloud Firestore,我面临这样一种情况:我希望检索字段值(计时)并将它们按排序顺序存储在ArrayList中,以便以后处理它们。我的文档中有24个值(00-23)。我希望在循环迭代时按升序存储索引中的值,例如,00的值应存储在TimeList(0)中,23的值应存储在TimeList(23)中。但循环运行速度比firebase代码快得多,而且我以无序的方式接收值 final DocumentReference docRef = db.collection("parent").document(child);

我面临这样一种情况:我希望检索字段值(计时)并将它们按排序顺序存储在ArrayList中,以便以后处理它们。我的文档中有24个值(00-23)。我希望在循环迭代时按升序存储索引中的值,例如,00的值应存储在TimeList(0)中,23的值应存储在TimeList(23)中。但循环运行速度比firebase代码快得多,而且我以无序的方式接收值

final DocumentReference docRef = db.collection("parent").document(child);
        docRef.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
            @Override
            public void onSuccess(DocumentSnapshot documentSnapshot) {

                  for(int tcounter=0;tcounter<24;tcounter++){
                      if(tcounter<10){
                          documentSnapshot.getString("0"+String.valueOf(tcounter)); 
                          timesList.add(documentSnapshot.getString("0"+String.valueOf(tcounter))); 
                      }
                      else{
                          documentSnapshot.getString(String.valueOf(tcounter));
                          timesList.add(documentSnapshot.getString(String.valueOf(tcounter)));
                          if(tcounter==23){
                              valuesdownloaded="yes";
                          }
                      }

                }
             }
        });
最终文档参考docRef=db.collection(“父”)文档(子);
docRef.get().addOnSuccessListener(新的OnSuccessListener()){
@凌驾
成功时公共无效(文档快照文档快照){

for(int tcounter=0;tcounter不一定是问题的解决方案,但此代码要短得多,并且与您当前所做的相同:

final DocumentReference docRef = db.collection("parent").document(child);
docRef.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
    @Override
    public void onSuccess(DocumentSnapshot documentSnapshot) {
        for(int tcounter=0;tcounter<23;tcounter++){
            String key = (tcounter<10) ? "0"+String.valueOf(tcounter) : String.valueOf(tcounter);
            timesList.add(documentSnapshot.getString(key)); 
        }
        valuesdownloaded="yes";
     }
});
最终文档参考docRef=db.collection(“父”)文档(子);
docRef.get().addOnSuccessListener(新的OnSuccessListener()){
@凌驾
成功时公共无效(文档快照文档快照){

对于(int tcounter=0;tcounter运行此代码时有什么问题?如果我调试它并逐步运行,它会给出所需的结果,但在正常运行模式下,输出会失真。例如,它可能在第8或第9个索引处存储00-35