[英]How can i print data in reverse order using firebase in android
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();
If you are using FirebaseUI please use the following lines of code: 如果您使用的是FirebaseUI,请使用以下代码行:
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setReverseLayout(true);
layoutManager.setStackFromEnd(true);
recyclerView.setLayoutManager(layoutManager)
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. 在这种情况下,将您的snapshotIterator中的所有元素添加到列表中,然后根据Collections的官方文档使用反向顺序(Comparator cmp),最后将其传递给适配器。 thanks to Mr. Alex Mamo
感谢Alex Mamo先生
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.