this.books = new ArrayList<>();
mFirebaseDatabaseReference.child(SellBooksPost).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange( DataSnapshot AdataSnapshot) {
for (final DataSnapshot AmessageSnapshot : AdataSnapshot.getChildren()) {
bFirebaseDatabaseReference.child(mUserId).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot BdataSnapshot) {
for (DataSnapshot BmessageSnapshot : BdataSnapshot.getChildren()) {
if (BmessageSnapshot.child("book").getValue().toString().equals(AmessageSnapshot.child("SellBooksPostId").getValue().toString())){
Log.d("INFO", "SELL BOOK book " + BmessageSnapshot.child("book").getValue());
Log.d("INFO", "SELL BOOK DETAIL " + AmessageSnapshot.child("SellBooksPostId").getValue());
books.add(new Book(
AmessageSnapshot.child("SellBooksPostId").getValue().toString(),
AmessageSnapshot.child("bookTitle").getValue().toString()
));
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
saleBookPostAdapter = new SaleBookPostAdapter(getApplicationContext(), books);
mRoomRecyclerView.setHasFixedSize(true);
mRoomRecyclerView.setAdapter(saleBookPostAdapter);
答案 0 :(得分:2)
很难说这是否是一个问题,但在更新数据后我没有看到调用RecyclerView.Adapter#notifyDataSetChanged()方法。所以试试吧
salesBookAdapter.notifyDataSetChanged()
后
books.add(new Book(
AmessageSnapshot.child("SellBooksPostId").getValue().toString(),
AmessageSnapshot.child("bookTitle").getValue().toString()
));