How to update a FirebaseRecyclerAdapter's quer

2019-01-15 16:48发布

If I have a Query a, and I'm setting it to a FirebaseRecyclerAdapter.

Then, I want to constantly create a new Query and update the FirebaseRecyclerAdapter.

E.G:

query = database.orderByChild("child");
query2 = database.orderByChild("child2"); 
adapter = new FirebaseRecyclerAdapter<...>(...,...,...,query){
   ...
}

Now, after 3 seconds, I'm looking for a method to change the query. Similar to this:

adapter.setQuery(query2);

Is there an existing method for this? Or was Firebase, like always, too lazy to even work on this?

2条回答
Emotional °昔
2楼-- · 2019-01-15 17:02

You can create a custom Adapter class to accomplish this but its not fully optimal. See: https://stackoverflow.com/a/53235783/683658

查看更多
beautiful°
3楼-- · 2019-01-15 17:24

Firebase Database queries are immutable: you cannot change the properties of an existing query.

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?

查看更多
登录 后发表回答