【发布时间】:2019-05-28 21:16:43
【问题描述】:
mFirestore.collection("notifications").orderBy("timestamp",Query.Direction.DESCENDING).addSnapshotListener(new EventListener<QuerySnapshot>(){
@Override
public void onEvent(@javax.annotation.Nullable QuerySnapshot documentSnapshots,@javax.annotation.Nullable FirebaseFirestoreException e){
if(e!=null){
Log.d(TAG,"Error : "+e.getMessage());
}
assert documentSnapshots!=null;
for(DocumentChange doc:documentSnapshots.getDocumentChanges()){
if(doc.getType()==DocumentChange.Type.ADDED){
String doc_id=doc.getDocument().getId();
NotificationModel Notifications=doc.getDocument().toObject(NotificationModel.class).withDocId(doc_id);
allNotifications.add(Notifications);
notificationAdapter.notifyDataSetChanged();
}
}
}
});
我正在尝试这样做,当在 Firestore 集合中添加一个新文档时,它将添加到 0 位置。但不是 0 位置,而是在最后一个位置添加一个新项目。
【问题讨论】:
标签: java android firebase android-studio google-cloud-firestore