如何更新 FirebaseRecyclerAdapter 的查询 [英] How to update a FirebaseRecyclerAdapter's query
问题描述
如果我有一个 Query a
,并且我将它设置为一个 FirebaseRecyclerAdapter
.
If I have a Query a
, and I'm setting it to a FirebaseRecyclerAdapter
.
然后,我想不断创建一个新的Query
并更新FirebaseRecyclerAdapter
.
Then, I want to constantly create a new Query
and update the FirebaseRecyclerAdapter
.
例如:
query = database.orderByChild("child");
query2 = database.orderByChild("child2");
adapter = new FirebaseRecyclerAdapter<...>(...,...,...,query){
...
}
现在,3 秒后,我正在寻找一种方法来更改查询.类似这样:
Now, after 3 seconds, I'm looking for a method to change the query. Similar to this:
adapter.setQuery(query2);
是否有现有的方法?还是 Firebase 像往常一样懒得做这件事?
Is there an existing method for this? Or was Firebase, like always, too lazy to even work on this?
推荐答案
Firebase 数据库查询是不可变的:您无法更改现有查询的属性.
Firebase Database queries are immutable: you cannot change the properties of an existing query.
由于 FirebaseUI 中的适配器主要是底层数据结构的反映,我们也没有添加更改现有适配器查询的选项.
Since the adapters in FirebaseUI are mostly a reflection of the underlying data structure, we have not added the option to change the query for an existing adapter either.
当我创建一个新的查询时,我也创建了一个新的适配器并将那个绑定到(列表或回收器)视图.
When I create a new query, I also create a new adapter and tie that to the (list or recycler) view.
您认为替换现有适配器下的查询比为新查询创建新适配器有什么优势?
What advantage do you see of replacing the query under the existing adapter over creating a new adapter for the new query?
这篇关于如何更新 FirebaseRecyclerAdapter 的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!