问题
i have a noticeboard activity to show to the notice. Now i want to print last notice at first position. Means in reverse order.
if (dataSnapshot.getValue() != null) {
Iterable<DataSnapshot> snapshotIterator = dataSnapshot.getChildren();
Iterator<DataSnapshot> iterator = snapshotIterator.iterator();
while (iterator.hasNext()) {
//notificationCount++;
DataSnapshot snapshot = iterator.next();
回答1:
If you are using FirebaseUI please use the following lines of code:
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setReverseLayout(true);
layoutManager.setStackFromEnd(true);
recyclerView.setLayoutManager(layoutManager)
回答2:
This is the answer.
In this case, add all the elements from your snapshotIterator to a list and use then reverseOrder(Comparator cmp) according to the offical doc of Collections and in the end pass it to the adapter. thanks to Mr. Alex Mamo
来源:https://stackoverflow.com/questions/46777129/how-can-i-print-data-in-reverse-order-using-firebase-in-android