本文介绍了如何从字段而不是整个文档中获取数据.消防处的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的Firebase Firestore上的字段获取数据,而不是整个文档.我想要的字段

I am trying to get data from fields on my firebase firestore, but not the whole document.Fields that i want

这是我的代码,可以获取整个文档.

Here is my code that get the whole document.

db.collection("Reminder").get()
            .addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
                @Override
                public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
                    if (!queryDocumentSnapshots.isEmpty()) {
                        List<DocumentSnapshot> list = queryDocumentSnapshots.getDocuments();

                        for (DocumentSnapshot d : list) {
                            dbReminder p = d.toObject(dbReminder.class);
                            p.setId(d.getId());
                            remtasklist.add(p);
                        }
                        adapter.notifyDataSetChanged();

                    }
                }
            });

先谢谢了.我更新了集合图片.集合

Thanks in advance. I updated with the collection pic.Collection

推荐答案

您可以从documentSnapshot获取特定字段.

You can get specific fields from the documentSnapshot.

 String location = documentSnapshot.getString("inLocation");
 String time = documentSnapshot.getString("time");//assuming time here is string
 String title = documentSnapshot.getString("title");

这篇关于如何从字段而不是整个文档中获取数据.消防处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-27 09:36