问题
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?
回答1:
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);
回答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);
来源:https://stackoverflow.com/questions/45879905/firebase-database-loop-through-children-starting-from-last-child