在我的应用程序中,我想在从 Firestore 获取数据之前添加加载布局。
所以我尝试添加 Snapsnot 监听器,但效果不佳。
我想知道我该怎么做。
最佳答案
为了能够使用 addSnapshotListener
,请尝试以下操作:
final DocumentReference docRef = db.collection("cities").document("SF");
docRef.addSnapshotListener(new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(@Nullable DocumentSnapshot snapshot,
@Nullable FirebaseFirestoreException e) {
if (e != null) {
Log.w(TAG, "Listen failed.", e);
return;
}
if (snapshot != null && snapshot.exists()) {
Log.d(TAG, "Current data: " + snapshot.getData());
} else {
Log.d(TAG, "Current data: null");
}
}
});
document()
返回 DocumentReference
,并且类 DocumentReference
包含方法 addSnapshotListener
关于java - 如何将 .addSnapShotListener 设置为 fragment 中的集合引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60630541/