I am developing an Android chat application in which I need to order the conversation details by the date. My firebase data structure is mentioned below.
Now I want to retrieve and show the data on the latest date on my RecyclerView from Firebase Realtime Database based on timestamp.
I have tried the following approaches.
final DatabaseReference nm =
        FirebaseDatabase.getInstance().getReference("Transaction");
Query query = nm.orderByChild("Date").limitToFirst(5);
;
query.addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
        listData.clear();
        if (dataSnapshot.exists()) {
            for (DataSnapshot npsnapshot : dataSnapshot.getChildren()) {
                Transaction ld = npsnapshot.getValue(Transaction.class);
                listData.add(ld);
            }
            Tadapter = new TransactionAdapter(listData);
            rv.setAdapter(Tadapter);
            Log.d(TAG, "Total Count" + Tadapter.getItemCount());
        }
    }
}

 
     
    