Firebase Database loop through children starting from last child

微笑、不失礼 提交于 2021-02-10 05:17:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!