0

So I am trying to show the most recent node on the top of the recyclerview

I want to add the most recent child to the top of the database so that i can retrieve them in the same order.

I know I can reverse the recyclerview .so that It will be shown in the correct order but I am using Firebase Pagination. which is causing issues

This is my database structure

So I want to add the most recent child to the top of this database, is it possible with any Algorithm or Firebase methods?

This is the code to add the data to the firebase

     FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();

    DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("Admin").
            child(firebaseAuth.getUid())
            .child("INSTITUTE").child("CLASSES").push();

    ClassesHelper classesHelper = new ClassesHelper(classnamestring,"Empty",time,"0",presentTeacherid);

    dialogprogressbar.setVisibility(View.GONE);

    databaseReference.setValue(classesHelper);

1 Answers1

1

You have two options:

  1. download the data in the ASC order nad reverse it on the client side. But as you said you have an issue with that because of the pagination.

  2. Add for each element a reversed timestamp like: 0 - Date.now() and use that as sort field. In that case all your elements would be returned in DESC order.

You can find more about that here and here.

Tarik Huber
  • 7,061
  • 2
  • 12
  • 18