I have this data in "Firestore", I want to get all documents according to "city" like all users who have city "karachi" and stored in arrayList
of type "chatModel" I want to show this data in recyclerView
Here is the image of dataabase:
I have tried this but it's only getting me the last document from collection.
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()
}
Here is the Logcat result:
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}
Here is the screenshot of all documents which contain the city "Karachi" but it's only getting the last one