title: Android - Firebase onChildAdded how to listen for all child
body: <p>I am having a problem of displaying the newly added data. My <code>onChildAdded</code> is listening for any new notification. This new notification is saved into Firebase. My notification contains 2 child (Message and Date).</p>
  
  <p>However, I'm able only to display one of the child (Date) when I add a new notification. I'm able to retrieve everything if I re-run the app but I want the changes to be made when I'm on the app itself. How can I show everything when I add a new notification? Is it because onChildAdded only listen for the previous child? If needed, I can post my adapter and getter/setter codes.</p>
  
  <p>Example: I sent 2 new notifications and the listener only reads the Date. Screenshot below.</p>
  
  <p><a href="https://i.stack.imgur.com/Qzkc0.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Qzkc0.jpg" alt="enter image description here"></a></p>
  
  <p>Not in order. It doesn't display the newly added notification "Message". I added "Hi2" and "Hi3".
  <a href="https://i.stack.imgur.com/QvvFS.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QvvFS.jpg" alt="enter image description here"></a></p>
  
  <p><strong>NotificationFragment.java</strong></p>
  
  <pre><code>public class NotificationFragment extends Fragment {
  
      private void prepareNotification1() {
          FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
          String userID = user.getUid();
  
  //        mRef.child("customers").child(userID).child("Notification").addListenerForSingleValueEvent(new ValueEventListener() {
  //            @Override
  //            public void onDataChange(DataSnapshot dataSnapshot) {
  //                for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
  //                    System.out.println(postSnapshot.getValue());
  //                    Notification menu = postSnapshot.getValue(Notification.class);
  ////                    Notification menu = new Notification(postSnapshot.getValue(String.class));
  //                    notificationList.add(menu);
  //                }
  //                mAdapter.notifyDataSetChanged();
  //            }
  //
  //            @Override
  //            public void onCancelled(DatabaseError databaseError) {
  //
  //            }
  //
  //        });
  //
  
  
          mRef.child("customers").child(userID).child("Notification").addChildEventListener(new ChildEventListener() {
              @Override
              public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                      Log.d("child", "onChildAdded:" + dataSnapshot.getKey());
                      Log.d("child", "onChildAdded:" + dataSnapshot.getValue());
                      Notification menu = dataSnapshot.getValue(Notification.class);
                  mAdapter.notifyDataSetChanged();
              }
          });
      }
  }
  </code></pre>
  
  <p><strong>FirebaseMessaging</strong></p>
  
  <pre><code>public class MyFirebaseMessagingService extends FirebaseMessagingService {
      private DatabaseReference mRef;
  
      @Override
      public void onMessageReceived(RemoteMessage remoteMessage) {
          final String uniqueID = UUID.randomUUID().toString();
  
          mRef.child("customers").child(userID).child("Notification").child(uniqueID).child("Date").setValue(notificationTime);
          mRef.child("customers").child(userID).child("Notification").child(uniqueID).child("Message").setValue(remoteMessage.getData().get("body"));
          createNotification(remoteMessage.getData().get("title"),remoteMessage.getData().get("body"));
  }
  </code></pre>
  
  <p><strong>Notification.java</strong></p>
  
  <pre><code>public class Notification {
      private String Message;
      private String Date;
  
  
      public Notification(){
      }
  
      public Notification(String Message, String Date){
          this.Message = Message;
          this.Date = Date;
      }
  
      public String getDate() {
          return Date;
      }
  
      public void setDate(String Date) {
          this.Date = Date;
      }
  
      public String getMessage() {
          return Message;
      }
  
      public void setMessage(String Message) {
          this.Message = Message;
      }
  }
  </code></pre>
  
  <p><strong>NotificationAdapter.java</strong></p>
  
  <pre><code>public class NotificationAdapter extends RecyclerView.Adapter&lt;NotificationAdapter.NotificationHolder&gt; {
      private List&lt;Notification&gt; notificationList;
      private Context mContext;
  
      public NotificationAdapter(Context mContext, List&lt;Notification&gt; notificationList) {
          this.mContext = mContext;
          this.notificationList = notificationList;
      }
  
  
      @Override
      public NotificationHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View inflatedView = LayoutInflater.from(parent.getContext())
                  .inflate(R.layout.list_item_notification, parent, false);
          return new NotificationHolder(inflatedView);
      }
  
      @Override
      public void onBindViewHolder(final NotificationHolder holder, int position) {
          Notification notification = notificationList.get(position);
          holder.body.setText(notification.getMessage());
          holder.time.setText(notification.getDate());
      }
  
      @Override
      public int getItemCount() {
          return notificationList.size();
      }
  
      public class NotificationHolder extends RecyclerView.ViewHolder {
          public TextView body;
          public TextView time;
  
          public NotificationHolder(View view) {
              super(view);
              body = (TextView) view.findViewById(R.id.bodyMsg);
              time = (TextView) view.findViewById(R.id.time);
          }
      }
  }
  </code></pre>