我正在 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();
}
});
最佳答案
我会怎么做?
当您将 JSON
插入到 firebase 时,添加另一个名为 timestamp
的字段,其中包含插入时间。
然后使用Query到 orderByChild('timestamp')
Query query = db.child("eventos").orderByChild("timestamp");
关于java - 获取更多最新数据 Firestore Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48358184/