将所有字段名称从 firestore 文档获取到数组列表 [英] Getting all field names form a firestore document to an arraylist
本文介绍了将所有字段名称从 firestore 文档获取到数组列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从文档中获取包含所有字段名称的 ArrayList
并将其转换为 ArrayList
.
I'm trying t get an ArrayList
with all the field names from a document and convert it to an ArrayList
.
我已经能够从一个集合中做到这一点,我将所有文档放在一个 ArrayList
中,但我不能从一个文档中做到这一点.
I've been able to do this from a collection where I put all the documents in a ArrayList
but I can't do it from a document.
下面是所有文档的代码和数据库的图像以及我想要的.
Below is the code for all the documents from a colection and an image of the data base and what I want.
names_clinics= new ArrayList<>();
mFirebaseFirestore = FirebaseFirestore.getInstance();
mFirebaseFirestore.collection("CodeClinic")
.get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (DocumentSnapshot document : task.getResult()) {
names_clinics.add(document.getId());
Log.d("CLINIC CODE", document.getId() + " => " + document.getData());
}
} else {
Log.d("CLINIC CODE", "Error getting documents: ", task.getException());
}
}
});
谢谢:D
推荐答案
要打印这些属性名称,请使用以下代码:
To print those property names, please use the following code:
FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
DocumentReference codesRef = rootRef.collection("CodeClinic").document("Codes");
codesRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
List<String> list = new ArrayList<>();
Map<String, Object> map = task.getResult().getData();
for (Map.Entry<String, Object> entry : map.entrySet()) {
list.add(entry.getKey());
Log.d("TAG", entry.getKey());
}
//Do what you want to do with your list
}
}
});
输出将是:
Clinica
FEUP
outra
这篇关于将所有字段名称从 firestore 文档获取到数组列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文