Using Firebase Library to send data to the server in the form Message(String, String)
added to the HashMap
Exampl
You could make it using a ChildEventListener
instead of a ValueEventListener
.
For example. I have a class called match with 3 string properties {id, name, photoUrl}
then I add all the values in a List
. Instead of using a for loop it works for me with this code.
Query queryRef = mDatabase.child("users").child(user.getUid()).child("matches");
ChildEventListener listener = new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String previousChildName) {
Match match = dataSnapshot.getValue(Match.class);
matchList.add(match);
mAdapter = new MatchAdapter(getContext(), matchList);
recyclerView.setAdapter(mAdapter);
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String previousChildName) {
Log.d("MESSAGEFRAGMENT", "CHILDCHANGE");
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
};
queryRef.addChildEventListener(listener);