2

I have this loop through children:

public void onDataChange(DataSnapshot snapshot) {
            for (DataSnapshot postSnapshot: snapshot.getChildren()) {
                przejazd = postSnapshot.getValue(Przejazd.class);
                System.out.println(przejazd.getAdres_koniec());
                przejazdList.add(przejazd);
                mAdapter.notifyDataSetChanged();
            }

        }

But I want to loop from last child to first child, how to do it?

Jkrr
  • 49
  • 1
  • 7
  • 1
    Why do not you reverse przejazdlist? This would give you the sa,e effect of looping from last to first child. – Maged Saeed Aug 25 '17 at 11:07

2 Answers2

2

From what I know, you can't do it with current API. If you want to reverse it, you can do it with the obtained list.

Collections.reverse(przejazdList);
Schidu Luca
  • 3,897
  • 1
  • 12
  • 27
2

You can't order your data in descending order in Firebase. Refer this link 1 and link 2

More convinient way would be reverse your list by

Collections.reverse(yourList);

AndiM
  • 2,196
  • 2
  • 21
  • 38