所以我仍在尝试使用我的应用程序并遇到另一个砖墙,我想找回最新的" bloodLevel"从这组数据中保存到firebase并将其输出到textview,我不确定如何做到这一点:
"BGRatio" : "1",
"CarbRatio" : "5",
"Entries" : {
"-KfcV3kfCMTcbeSa9Wv6" : {
"BloodLevels" : "7.5",
"Carbohydrates" : "20",
"DateandTime" : "19 Mar 2017, 21:36:47",
"Insulin" : "4.5"
},
"-KfcX05Fo2XDYLAkrBW-" : {
"BloodLevels" : "14",
"Carbohydrates" : "65",
"DateandTime" : "19 Mar 2017, 21:45:17",
"Insulin" : "20.0"
},
"-KfcrF6dKSolRl36dn4u" : {
"BloodLevels" : "12",
"Carbohydrates" : "90",
"DateandTime" : "19 Mar 2017, 23:18:03",
"Insulin" : "23.0"
},
"-Kfeqt1T27RKSNMkZrYA" : {
"BloodLevels" : "24",
"Carbohydrates" : "10000",
"DateandTime" : "20 Mar 2017, 08:35:43",
"Insulin" : "2017.0"
},
"-Kg4DU0eM8sx9uIHbDL4" : {
"BloodLevels" : "13.3",
"Carbohydrates" : "50",
"DateandTime" : "Mar 25, 2017, 11:28:54 AM",
"Insulin" : "16.3"
},
"-KgIxNJNSDpTAKpo62hn" : {
"BloodLevels" : "8.0",
"Carbohydrates" : "40",
"DateandTime" : "Mar 28, 2017, 9:08:30 AM",
"Insulin" : "9.0"
},
"-KgOJ-4eGU5z_dTuxfoq" : {
"BloodLevels" : "10",
"Carbohydrates" : "50",
"DateandTime" : "Mar 29, 2017, 10:05:25 AM",
"Insulin" : "13.0"
}
},
"Ideal Level" : "7"
}
对此的任何帮助都会很棒,谢谢!
答案 0 :(得分:2)
您应该将DateandTime保存为时间戳,以便orderByChild('DateandTime')
在其上,然后使用limitToLast(1)
选择最后一个。
https://firebase.google.com/docs/reference/android/com/google/firebase/database/Query.html#orderByChild(java.lang.String) https://firebase.google.com/docs/reference/android/com/google/firebase/database/Query#limitToLast(int)