2016-12-01 43 views
-3
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() 
)); 
+0

感謝的andrei_zaitcev的簡要說明。我只是解決了這個問題。我在函數之外的setadapter上做了一個愚蠢的錯誤。 –