在列表中获取文档中的所有字段-Firestore Java [英] Get all fields in a document in a list - Firestore Java
本文介绍了在列表中获取文档中的所有字段-Firestore Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将所有字段从文档移到ListView
.我已经尝试过foreach循环,但无法正常工作.
I am trying to get all fields from a document to a ListView
. I have tried foreach loop but it is not working.
dbRef.collection("Shopkeeper Own Shops").document("Shopkeeper@gmail.com")
.get()
.addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
// Get all fields to a list
}
});
推荐答案
要将文档中所有属性的所有值添加到列表中,请使用以下代码行:
To add all the value of all properties within a document to a list, please use the followig lines of code:
dbRef.collection("Shopkeeper Own Shops").document("Shopkeeper@gmail.com").get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document.exists()) {
List<String> list = new ArrayList<>();
Map<String, Object> map = document.getData();
if (map != null) {
for (Map.Entry<String, Object> entry : map.entrySet()) {
list.add(entry.getValue().toString());
}
}
//So what you need to do with your list
for (String s : list) {
Log.d("TAG", s);
}
}
}
}
});
这篇关于在列表中获取文档中的所有字段-Firestore Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文