java如何设置。将SnapshotListener添加到片段中的集合引用 1 周,5 日 Questions & Answers 1131 在我的应用程序中,我想在从Firestore获取数据之前添加一个加载布局 所以我尝试添加Snapsnot listener,但效果不好 我想知道我该怎么做
# 1 楼答案 要能够使用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包含方法addSnapshotListener
# 1 楼答案
要能够使用
addSnapshotListener
,请尝试以下操作:document()
返回一个^{DocumentReference
包含方法addSnapshotListener