【发布时间】:2018-12-13 14:44:49
【问题描述】:
我有一个具有类似结构的 Firebase 项目
CollectionReference adminList;
adminList = mFirestore.collection("AdminList");
Map<String,Object> k = new HashMap<>();
k.put("order",order);
k.put("status","New Order");
k.put("hotel_name",username.getText().toString());
k.put("user_id",mUid);
k.put("time", "Select Time");
//adminList.document(order).set(k);
adminList.document(mUid).collection("User").document(order).set(k);
可以有多个用户及其 UserId。我必须在列表中检索它。
为此,我使用了以下代码。
@Override
protected void onStart() {
super.onStart();
mFirestore.collection("AdminList").getParent().collection("Users").addSnapshotListener(MainActivity.this, new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
orderList.clear();
assert queryDocumentSnapshots != null;
List<OrderList> types = queryDocumentSnapshots.toObjects(OrderList.class);
orderList.addAll(types);
adapter = new AdminListAdapter(MainActivity.this,orderList);
recyclerView.setAdapter(adapter);
}
});
}
但我需要一种访问子集合及其文档的方法,以便我可以在我的 recyclerview 中检索列表。
【问题讨论】:
-
能否请您添加您的数据库结构并指出您想要获取哪些值以及您想要添加到 ArrayList 中?
-
我已经上传了截图请看
-
这很好,但请指出您想要获取哪些值以及您想要添加到 ArrayList 中?
hotel_name、order等等,对吗?
标签: android firebase google-cloud-firestore