How to update a FirebaseRecyclerAdapter's query

為{幸葍}努か 提交于 2019-12-05 21:13:54

问题


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?


回答1:


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?




回答2:


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



来源:https://stackoverflow.com/questions/39085182/filter-data-on-firebase-using-searchview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!