java - 获取更多最新数据 Firestore Android

标签 java android firebase google-cloud-firestore

我正在 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 的字段,其中包含插入时间。

然后使用QueryorderByChild('timestamp')

 Query query = db.child("eventos").orderByChild("timestamp");

关于java - 获取更多最新数据 Firestore Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48358184/

相关文章:

java - androidx.appcompat.widget.AppCompatTextView 无法转换为 android.widget.CheckedTextView

node.js - Cloud Functions 中的 Cloud Firestore

java - AdvertisingIdClient getAdvertisingIdInfo 被主线程阻塞

java - 未知来源的 Proguard 和 Libgdx NullPointerException

android - 验证 Android 位图是 GrayScale

android - 从 android 中的谷歌地图中删除谷歌文本

ios - 当我将它设置为每封电子邮件一个时,Firebase 创建多个帐户

javascript - 在使用 Promise.all() forEach 渲染 NodeJS 页面之前等待 Firebase 数据加载

java - 如何摆脱 java.lang.RuntimeException : Unable to locate the App Engine agent in Eclipse Helios?

java - 来自不同 ClassLoader 的 Drools KieContainer