Reputation: 331
Currently, i can sort my documents in a Query, with it's:
query = anuncioRef.orderBy(campo, Query.Direction.DESCENDING).limit(100);
options = new FirestoreRecyclerOptions.Builder<AnuncioPrincipal>().setQuery(query,
AnuncioPrincipal.class).build();
adapter = new AnuncioAdapter(options);
RecyclerView recyclerView = root.findViewById(R.id.recyclerCadAnun);
recyclerView.setLayoutManager(new LinearLayoutManager(context));
recyclerView.setAdapter(adapter);
This works fine, but, i need that it change when the user click on button, i need that var "campo" must be changed to "dataPreco" and the list in recycler view must be updated:
botaoFiltrar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
campo = "dataAnuncio";
}
});
In spite of "campo" be changed to "dataAnuncio", the recyclerView still remains equals.
I need that the button click, the recyclerView change to the new query orderBy() method.
Upvotes: 0
Views: 160
Reputation: 599766
The FirestoreRecyclerAdapter
has an updateOptions
method that you can call to update the options.
So you could call that with something like:
query = anuncioRef.orderBy(campo, Query.Direction.DESCENDING).limit(100); // new campo
options = new FirestoreRecyclerOptions.Builder<AnuncioPrincipal>().setQuery(query, AnuncioPrincipal.class).build();
adapter.updateOptions(options);
Upvotes: 1