我有问题,因为在另一个异步事件中有异步事件。我想等待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);
}
});