【发布时间】:2021-04-24 06:18:10
【问题描述】:
我想从 Firebase Realtime Firebase DB 中获取患者在“CurrentDate”到 2 个月“PreviousDate”之间的病历。我面临的问题是日期正在进入我将通过调试代码检查的查询。这是我将获得“CurrentDate”和“PreviousDate”的代码:
date = Calendar.getInstance().time;
val dateFormat = SimpleDateFormat("d-M-yyyy")
currentDate = dateFormat.format(date)
cDate.text = currentDate //this gives me **24-4-2021**
val calendar = Calendar.getInstance()
calendar.add(Calendar.MONTH, -2)
val preDate = calendar.time
previousDate = dateFormat.format(preDate)
pDate.text = previousDate /// this gives me **24-2-2021**
这是我为获取记录而编写的以下函数的代码:
private fun browseAppointmentByDate() {
mFirebaseInstance = FirebaseDatabase.getInstance()
appointmentDBReference = mFirebaseInstance!!.reference
completeAppointArrayList = ArrayList()
val ref = FirebaseDatabase.getInstance()
ref.getReference("PatientChecked").child(currentUserID).orderByChild("date").startAt(previousDate)
.endAt(currentDate)
.addListenerForSingleValueEvent(object : ValueEventListener {
override fun onDataChange(doctorList: DataSnapshot) {
try {
completeAppointArrayList?.clear()
for (eachDoctor in doctorList.children) {
Log.e("TAG", "onDataChange: " + eachDoctor.value.toString())
var patientsListModel: CheckPatientModel = eachDoctor.getValue(CheckPatientModel::class.java)!!
completeAppointArrayList!!.add(patientsListModel)
}
if (completeAppointArrayList == null || completeAppointArrayList!!.size == 0) {
txtNoCompAppointFound!!.visibility = View.VISIBLE
txtNoCompAppointFound.text = "You have no recent appointment!!"
pbCompAppointment!!.visibility = View.GONE
} else {
txtNoCompAppointFound.visibility = View.GONE
pbCompAppointment!!.visibility = View.GONE
}
mCompleteAppointmentAdapter = CompleteAppointmentAdapter(activity, completeAppointArrayList)
rvCompletedAppoint!!.adapter = mCompleteAppointmentAdapter
} catch (e: Exception) {
Log.e("TAG", "onDataChange: $e")
} catch (e: Exception) {
Log.e("TAG", "onDataLoad: $e")
pbCompAppointment!!.visibility = View.GONE
}
}
override fun onCancelled(error: DatabaseError) {
Log.w(ContentValues.TAG, "loadPost:onCancelled", error.toException())
}
})
}
这是我的 Firebase 数据库的结构,在当前日期和上一个日期之间,至少我会得到 23-4-2021 的记录,但它没有显示。
【问题讨论】:
标签: android firebase kotlin firebase-realtime-database