In my FireStore Recycler Java Android app, I want to display the documents of a collection ordered differently depending on whether displayList = false or displayList = true is set. That boolean value is changed by the user clicking a buttonView in the same activity. The same click then executes the method setUpRecyclerView() (see code below), to "refresh" the Recycler.
The app starts up with displayList = false. As the method setUpRecyclerView() is also run in onCreate(), the Recycler shows all the documents ordered according to "categoryNumber". Perfect.
However, when the buttonView is clicked (changes to displayList = true), the Recycler turns empty. Also, after again clicking (changing to the original state of displayList = false), the Recycler remains empty. Still, the Log.d expressions indicate that the if {} else {} expression has been properly run through after both clicks, without any error messages.
It's as if setUpRecyclerView() can only be run once, at the start of the activity.
Please advise.
private void setUpRecyclerView(){
if (!displayList) {
Query query = collectionRef
.orderBy("categoryNumber", Query.Direction.ASCENDING);
FirestoreRecyclerOptions<Item> options = new FirestoreRecyclerOptions.Builder<Item>()
.setQuery(query,Item.class)
.build();
adapter = new ItemAdapter(options);
Log.d(TAG, "setUpRecyclerView: list false");
} else {
Query query = collectionRef
.orderBy("itemName", Query.Direction.ASCENDING);
FirestoreRecyclerOptions<Item> options = new FirestoreRecyclerOptions.Builder<Item>()
.setQuery(query,Item.class)
.build();
adapter = new ItemAdapter(options);
Log.d(TAG, "setUpRecyclerView: list true");
}
RecyclerView recyclerView = findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
adapter.setOnItemClickListener(new ItemAdapter.OnItemClickListener() { ... }