ThunderRoid ThunderRoid - 6 months ago 117
Android Question

Best way to change data on FirebaseRecyclerAdapter

currently I am using FirebaseRecyclerAdapter to represent data on a RecyclerView using the following Firebase query:

postsQuery = mDatabase.child("lists_new”).orderByKey().limitToFirst(10);

My RecyclerView has a header with 2 buttons: New List, Old List.
New list is loaded by default, and my question is, when the user taps the Old List button, what is the most efficient way to replace the new list with old list.

The Firebase query for the old list looks like this:

postsQuery = mDatabase.child("lists_old”).orderByKey().limitToFirst(10);

Note: both new list and the old list has the same data types, i.e. they share the same Java POJO class and the the same layout.


You will need a new adapter and attach that to the same RecyclerView.

So after constructing the new query, you create a new adapter and attach it to the view:

adapter = new FirebaseRecyclerAdapter<Chat, ChatHolder>(
   Chat.class, android.R.layout.two_line_list_item, ChatHolder.class, postsQuery) {