简体   繁体   English

如何根据本地或数据库中的字段值更改更新 Firestore RecyclerView 适配器?

[英]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.

相关问题 如何更新 Firestore 文档中特定字段的值? - How to update value of a specific field in Firestore document? 当我更新 firestore 数据库时,为什么我的适配器没有更改 TextView 的值? - Why is my adapter is not changing the value of TextView when I update the firestore database? 如何更新 firestore 数据库中的嵌套字段? - How can I update a nested field in a firestore database? 如何更新 Firestore 字段以为其提供空值(未定义或 null)? - How to update a Firestore field to give it an empty value (undefined or null)? 尝试更新 firestore 数据库中的单个字段 - Trying to update a single field in a firestore database 从适配器 class 中删除项目时如何更新 recyclerview - how to update recyclerview when delete an item from adapter class 在 Firestore 中更新 object 中的字段? - Update a field in an object in Firestore? Kotlin + Firestore:如何为firestore数据库的某些数据添加字段? - Kotlin + Firestore: How to add field to certain data of firestore database? 如何在 python 中增加 Firestore 字段值? - How to increment Firestore field value in python? 如何检查firestore数据库中的文档中是否存在字段? - how to check if Field exist in document in firestore database?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM