我在Android上使用社交网络类型的应用。我的项目已连接到Firebase。一切都很完美。但我需要这样的例子,这些出版物是从最新的到最早的。我正在使用Cloud Firestore。
FirebaseFirestore db = FirebaseFirestore.getInstance();
CollectionReference collectionReference = db.collection("eventos");
collectionReference.limit(2).get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot documentSnapshots) {
datos.removeAll(datos);
for (DocumentSnapshot document : documentSnapshots.getDocuments()) {
Map<String, Object> mapaEvento = document.getData();
vento evento = new Evento((String) mapaEvento.get("usuario"), (String) mapaEvento.get("titulo"), (String) mapaEvento.get("categoria"));
datos.add(evento);
}
adaptadorRecyclerHome.notifyDataSetChanged();
}
});
答案 0 :(得分:1)
我会怎么做?
向firebase插入timestamp
时,请添加另一个名为orderByChild('timestamp')
的字段,该字段具有插入时间。
然后使用Query到 Query query = db.child("eventos").orderByChild("timestamp");
{{1}}