【发布时间】:2020-02-25 12:42:49
【问题描述】:
我在“Firestore”中有这些数据,我想根据“城市”获取所有文档,就像所有拥有城市“卡拉奇”并存储在“chatModel”类型的arrayList 中的用户一样,我想在其中显示这些数据回收站视图
我已经尝试过了,但它只能从集合中获取最后一个文档。
firestore.collection("USERS")
.whereEqualTo("city",cityName)
.get()
.addOnSuccessListener { documents ->
for (document in documents) {
arrayList.add(document.toObject(chatModel::class.java))
Log.i("Info", "${document.id} => ${document.data}")
}
val adapter = chatAdapter(context!!, arrayList)
chatRecyclerView.layoutManager = LinearLayoutManager(context,
LinearLayoutManager.VERTICAL,false)
chatRecyclerView.adapter = adapter
adapter.notifyDataSetChanged()
}
这是 Logcat 结果:
v21GH5sBi3SdIb3v3xsp3ob64S23 => {username=Muhammad Rizwan, Email=mr1017753@gmail.com, city=Karachi, ProfileImageUrl=https://firebasestorage.googleapis.com/v0/b/me2wee-1b547.appspot.com/o/USERS-MEDIA%2Fv21GH5sBi3SdIb3v3xsp3ob64S23?alt=media&token=193c4013-c580-45dc-b63d-fee1ef13caba}
这是包含城市“卡拉奇”的所有文档的屏幕截图,但它只获取最后一个
【问题讨论】:
标签: android firebase kotlin google-cloud-firestore