我正在尝试通过调用检索文档 ID doc.getId(),但无法从此代码调用它
db.collection("Pegawai").addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
if(e != null) {
Log.d(TAG, e.toString());
}
if (queryDocumentSnapshots != null) {
for (DocumentChange doc: queryDocumentSnapshots.getDocumentChanges()) {
if (doc.getType() == DocumentChange.Type.ADDED) {
Pegawai pegawai = doc.getDocument().toObject(Pegawai.class);
pegawai.setId(doc.getId());
pegawaiList.add(pegawai);
pegawaiListAdapter.notifyDataSetChanged();
}
}
}
}
});
我试过这段代码,显然,我可以用这段代码调用,但这段代码根本doc.getId()没有填充我的代码recyclerview
db.collection("Pegawai").addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
if(e != null) {
Log.d(TAG, e.toString());
}
if (queryDocumentSnapshots != null) {
for (DocumentSnapshot doc : queryDocumentSnapshots) {
Pegawai pegawai = doc.toObject(Pegawai.class);
pegawai.setId(doc.getId());
pegawaiList.add(pegawai);
}
}
}
});
炎炎设计
侃侃无极
慕丝7291255
相关分类