[英]How to update Firestore RecyclerView Adapter based upon field value changes locally or in database?
I'm trying to reload or update Firestore Recyclerview Adapter (Firebase Ui) based upon field value changes.我正在尝试根据字段值更改重新加载或更新 Firestore Recyclerview Adapter (Firebase Ui)。
In my case I'm querying .whereNotIn("id", list)
where list is stored locally and updated frequently which should trigger firestore recyclerview options based upon arraylist value updated.在我的例子中,我正在查询
.whereNotIn("id", list)
,其中列表存储在本地并经常更新,这应该根据更新的 arraylist 值触发 firestore recyclerview 选项。
My code is below:我的代码如下:
postsRef
.orderBy("id")
.whereNotIn("id", list) // list is updated frequently so update firesttore recyclervew option
.whereEqualTo("disabled", false)
.whereEqualTo("expired", false)
.whereEqualTo("locality", locality)
.whereEqualTo("country", country)
.orderBy("createdAt", Query.Direction.DESCENDING)
.limit(20)
val firestoreRecyclerOptions: FirestoreRecyclerOptions<Post> =
FirestoreRecyclerOptions.Builder<Post>()
.setQuery(query, Post::class.java)
.build()
"list" value is changes locally frequently. “列表”值在本地经常更改。 I want to update firestore RecyclerView options maybe reload based upon list update.
我想更新 firestore RecyclerView 选项,可能会根据列表更新重新加载。
The list is updated as the data in the table is updated.该列表随着表中数据的更新而更新。
The code I wrote for myself, you can change it according to you.我自己写的代码,大家可以根据自己的情况改。
docRef
.whereEqualTo(field, equel)
.whereEqualTo(cevapField, cevapdurum)
.orderBy("date",query)
.addSnapshotListener { querySnapshot, firebaseFirestoreException ->
firebaseFirestoreException?.let {
Toast.makeText(context, it.message, Toast.LENGTH_LONG)
.show()
//error
return@addSnapshotListener
}
val listData: MutableList<Any> = mutableListOf()
querySnapshot?.let {
for (document in it) {
//success
val data1=document.getString("data1")
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.