I am performing multiple times of filter to the data in Firebase Realtime Database. For example, I first filter for people less than age 20, if the result count is less than 50, I will need to re-visit the database to filter again for people less than age 30, etc... Hence, I need to use addChildEventListener
multiple times.
The list of people who are selected will then be displayed in a RecyclerView.
I do that using this:
adapter = new Adapter(this, getListFromFirebase());
view= findViewById(R.id.my_view);
view.setLayoutManager(manager);
view.setAdapter(adapter);
Where getListFromFirebase()
is a function that use addChildEventListener
to get data from Firebase Realtime Database.
However, since Firebase Realtime Database is asynchronous, it always returns an empty list to the RecyclerView when the RecyclerView is initialized. Is there any way that I can make sure that I can successfully get the list that I want from Firebase Realtime Database before entering the RecyclerView?