【发布时间】:2018-06-20 12:17:35
【问题描述】:
这是我的代码(我认为问题出在 notifydatasetchanged 以及应该放在哪里):
FirebaseFirestore db = FirebaseFirestore.getInstance();
CollectionReference db1=db.collection("Joboffers");
db1.addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(QuerySnapshot documentSnapshots, FirebaseFirestoreException e) {
String empid = "";
for ( DocumentChange snapshot : documentSnapshots.getDocumentChanges())
{
if (snapshot.getType()==DocumentChange.Type.ADDED) {
empid = snapshot.getDocument().getId();
Log.d("employerid",empid);
}
FirebaseFirestore db = FirebaseFirestore.getInstance();
CollectionReference db2 =db.collection("Joboffers").document(empid).collection("Offers");
db2.addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(QuerySnapshot documentSnapshots, FirebaseFirestoreException e) {
for (DocumentChange snapshot1 : documentSnapshots.getDocumentChanges()) {
JO jo=new JO();
if (snapshot1.getType() == DocumentChange.Type.ADDED) {
jo = snapshot1.getDocument().toObject(JO.class);
String s=jo.getPoste().toString();
Log.d("poste",s);
postelist.add(jo);
jolistadapter.notifyDataSetChanged();
}
}
}
});
}
MList.setAdapter(jolistadapter);
}
});
这是我的 Firestore 收藏:
【问题讨论】:
-
你想达到什么目的?考虑添加代码的预期结果。
-
我正在尝试查看我收藏中的所有文档,所以我使用了 2 个快照
-
我在 logcat 中得到了我想要的结果,但我没有在我的回收站视图中得到它们,我只得到第一个文档
-
这听起来很奇怪。如果你在
postelist.add(jo)上设置一个断点并在调试器中运行,你能看到它在列表中添加了额外的项目吗? -
@FrankvanPuffelen,“Log.d”向我展示了“Poste”字段的值,但是在模拟器 recyclerview 中我只得到一个
标签: android google-cloud-firestore android-recyclerview