有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Android异步问题中的java异步

我有问题,因为我在另一个异步事件中有异步事件。我想等待来自upload.setPhone的结果,然后执行以下操作

upload.setName(doc.getString("text"));
                        upload.setImageUrl(doc.getString("photo"));...

" 我读了这篇How to return a DocumentSnapShot as a result of a method?,但问题是我要处理嵌套事件:/现在我得到这样的结果Logcat

   databaseReference.collection("advertisements")
            .whereEqualTo("userId",FirebaseAuth.getInstance().getUid())
            .addSnapshotListener(new EventListener<QuerySnapshot>() {
                @Override
                public void onEvent(@javax.annotation.Nullable QuerySnapshot snapshots, @javax.annotation.Nullable FirebaseFirestoreException e) {
                    if (e != null) {
                        System.err.println("Listen failed:" + e);
                        return;
                    }
                    Log.d(TAG, "Zero" );
                    for (final DocumentSnapshot doc : snapshots) {
                        Log.d(TAG, "First");

                        final Upload upload = new Upload();
                        databaseReferenceUsers.collection("users").document(doc.getString("userId")).addSnapshotListener(new EventListener<DocumentSnapshot>() {
                            @Override
                            public void onEvent(@javax.annotation.Nullable DocumentSnapshot documentSnapshot, @javax.annotation.Nullable FirebaseFirestoreException e) {
                                upload.setPhone(Integer.toString(documentSnapshot.getLong("phone").intValue()));
                                Log.d(TAG, "Second" );
                                Log.d(TAG, "Third" );
                                upload.setName(doc.getString("text"));
                                upload.setImageUrl(doc.getString("photo"));
                                upload.setKind(doc.getString("kind"));
                                upload.setType(doc.getString("type"));
                                upload.setPrice(doc.getString("price") + "zł");

                                upload.setVoivodeship(doc.getString("voivodeship"));
                                upload.setVariety(doc.getString("variety"));


                                mUploads.add(upload);
                                Log.d(TAG, "fourth" );
                            }
                        });


                    }
                    Log.d(TAG, "fifth" );
                    imageAdapter = new ImageAdapter(MyAdvertisementsActivity.this,mUploads);
                    recyclerView.setAdapter(imageAdapter);
                    progressCircle.setVisibility(View.INVISIBLE);

                }
            });

共 (0) 个答案