I am trying to create a chat using the Firebase-UI library for Cloud Firestore. This github repository contains the relevant code which I am using. The problem comes with th
To solve this, you can use the following query:
Query sChatQuery = sChatCollection
.orderBy("timestamp", Query.Direction.ASCENDING)
.whereGreaterThanOrEqualTo("timestamp', desiredTime)
.limit(50);
If you are using a RecyclerView
to display data, the simplest way would be to use the following code:
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setReverseLayout(true);
layoutManager.setStackFromEnd(true);
recyclerView.setLayoutManager(layoutManager);
This approch will reverse you the order as you want.
Another approach would be to create your own adapter that extends FirebaseListAdapter
and override getItem()
method like this:
@Override
public HashMap getItem(int pos) {
return super.getItem(getCount() - 1 - pos);
}
Another approach would be to get the data from the database, add it to a Collection
, a List
would be a good solution and then use Collections.reverse(yourList);
.