Попробуйте это
private List<Parties> newsList = new ArrayList<>();
db.collection("dbref").orderBy("name", Query.Direction.ASCENDING).addSnapshotListener(this,new EventListener<QuerySnapshot>() {
@Override
public void onEvent(QuerySnapshot documentSnapshots, FirebaseFirestoreException e) {
for (DocumentChange doc: documentSnapshots.getDocumentChanges()){
String id = doc.getDocument().getId();
NewsFeed news = doc.getDocument().toObject(NewsFeed.class).withId(id);
switch (doc.getType()) {
case ADDED:
newsList.add(news);
mAdapter.notifyDataSetChanged();
break;
case MODIFIED:
newsList.remove(news);
newsList.add(news);
mAdapter.notifyDataSetChanged();
break;
case REMOVED:
newsList.remove(news);
mAdapter.notifyDataSetChanged();
break;
}
}
}
});
Pojo будет
public class NewsFeed {
String userEmail,itemTitle,itemDescription,itemId,itemPrice,itemImageURL,
itemQuantity,itemStatus;
public NewsFeed(String userEmail, String itemTitle, String itemDescription, String itemId, String itemPrice, String itemImageURL) {
this.userEmail = userEmail;
this.itemTitle = itemTitle;
this.itemDescription = itemDescription;
this.itemId = itemId;
this.itemPrice = itemPrice;
this.itemImageURL = itemImageURL;
}
public NewsFeed() {
}
public String getUserEmail() {
return userEmail;
}
public void setUserEmail(String userEmail) {
this.userEmail = userEmail;
}
public String getItemTitle() {
return itemTitle;
}
public void setItemTitle(String itemTitle) {
this.itemTitle = itemTitle;
}
public String getItemDescription() {
return itemDescription;
}
public void setItemDescription(String itemDescription) {
this.itemDescription = itemDescription;
}
public String getItemId() {
return itemId;
}
public void setItemId(String itemId) {
this.itemId = itemId;
}
public String getItemPrice() {
return itemPrice;
}
public void setItemPrice(String itemPrice) {
this.itemPrice = itemPrice;
}
public String getItemImageURL() {
return itemImageURL;
}
public void setItemImageURL(String itemImageURL) {
this.itemImageURL = itemImageURL;
}
public String getItemQuantity() {
return itemQuantity;
}
public void setItemQuantity(String itemQuantity) {
this.itemQuantity = itemQuantity;
}
public String getItemStatus() {
return itemStatus;
}
public void setItemStatus(String itemStatus) {
this.itemStatus = itemStatus;
}
}