If you are passing an arraylist to the recyclerView you can do something like this:
FirebaseDatabase.getInstance().getReference().child("parent_id")
.child("id").orderByChild("count");
tpDBListener = tpDatabaseRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
tpUploads.clear();
for(DataSnapshot postSnapshot : snapshot.getChildren()){
newUpload pupload = postSnapshot.getValue(newUpload.class);
pupload.setKey(postSnapshot.getKey());
tpUploads.add(pupload);//add new object on end
//tpUploads.add(0,pupload);//add new object at beginning
}
tpAdapter.notifyDataSetChanged();
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
Toast.makeText(home.this, error.getMessage(),Toast.LENGTH_SHORT).show();
}
});
to flip the order so first is last and last is first I recommend when putting the value in the database putting it as 9999999999 and then -1 for what ever ordering you want then use the:
if you are not ordeing them by a value or a child.
tpUploads.add(0, pupload);//add new object at beginning
if you want to order by a value this is the better approach and initialize it in db as 9999999999 and then -1 for its value
.orderBy("child_ID")
firebase will try to read each digit for example 1 is before 6 but 10 will also come before 6 because of the first digit. That is why I start off with 9999999999 as the starting value and decrease acordingly