大家好,您能帮我解决我的问题吗?我需要在子文档的TextView
中显示所有数据(“时间”)。帮帮我,我是菜鸟。
db3.collection("Blood_Glucose").document(uid).collection("Date").document(date).collection("Time").document(time).set(answer);
答案 0 :(得分:1)
要获取该文档中的数据,您必须进行get()
调用并附加一个侦听器,如以下代码行所示:
DocumentReference timeRef = db3.collection("Blood_Glucose").document(uid)
.collection("Date").document(date)
.collection("Time").document(time);
假设:
uid = rom.reyes2398@yahoo.com
date = December 04, 2019
time = 03:15 AM
例如,要获取Result
的值,请使用以下代码行:
timeRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document.exists()) {
String result = document.getString("Result");
String date = document.getString("Date");
String time = document.getString("Time");
Log.d(TAG, result + " / " + date + " / " + time);
} else {
Log.d(TAG, "No such document");
}
} else {
Log.d(TAG, "get failed with ", task.getException());
}
}
});
您的logcat中的结果将是:
Risk of Having HyperGlycemia / December 04, 2019 / 03:15 AM