这是我的代码:
db.getFirestore().document("state/Madhya Pradesh/cities").get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
DocumentSnapshot documentSnapshot=task.getResult();
}
});
答案 0 :(得分:0)
为了从firestore中获取数组,请执行以下操作:-
DocumentReference documentReference = firestore.collection("states").document(uid);
documentReference.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot){
if(documentSnapshot.exists()){
ArrayList<String> arrList = new ArrayList<String>();
arrList = (ArrayList) documentSnapshot.get("cities");
for(int i=0;i<arrList.size();i++){
//Traversing the list
}
}
}
答案 1 :(得分:0)
请检查以下代码。希望对您有帮助
db.collection("Collection name").document("Document Id")
.collection("Collection name").get().addOnCompleteListener {
if (it.isSuccessful) {
if (it.result.isEmpty) {
//List is empty
} else {
val result = it.result.documents.map { it.toObject(YourModelClass::class.java)!! }
//Performe array list operation
// result is your array list
}
} else {
it.exception?.let {
//Print exception
}
}
}