Hi I am trying to populate recycler view by getting data from two different nodes in firebase. However I am getting two separate listings... one of each node. I want to combine them and show as a single item. My original question is posted here if more files are required to be seen : Populating Recycler View From Nested Queries in Firebase
My Fragement is as follows
// Firebase
fbDatabaseRootNode = FirebaseDatabase.getInstance().getReference();
fbDatabaseRefGroupList = fbDatabaseRootNode.child("groups_list").child(current_user_id);
fbDatabaseRefGroups = fbDatabaseRootNode.child("groups");
fbDatabaseRefGroupList.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
// Array to Get Group List
lGroupsList = new ArrayList<>();
if (dataSnapshot.exists()) {
// Clear Array to Get Group List
lGroupsList.clear();
for (DataSnapshot glSnapshot : dataSnapshot.getChildren()) {
// Use The Model To Format Array List and Pass It Into It
GroupsListModel g = glSnapshot.getValue(GroupsListModel.class);
// Array to Get Group List
lGroupsList.add(g);
// Get The Group ID To Get Data From Other Nodes
String groupID = String.valueOf(glSnapshot.getKey());
fbDatabaseRefGroups.child(groupID).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
// Array to Get Group List
lGroupsList2 = new ArrayList<>();
if (dataSnapshot.exists()) {
// Clear Array to Get Group List
lGroupsList2.clear();
// String groupName = (String) dataSnapshot.child("group_name").getValue();
// String groupTagLine = (String) dataSnapshot.child("group_tagline").getValue();
// String groupMemberCount = (String) dataSnapshot.child("group_member_count").getValue();
// Use The Model To Format Array List and Pass It Into It
GroupsListModel g = dataSnapshot.getValue(GroupsListModel.class);
// Array to Get Group List
lGroupsList2.add(g);
// Joining The Arrays To Get One Array
lGroupsList.addAll(lGroupsList2);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
}
aGroupList = new GroupsListAdapter(getContext(), lGroupsList);
rvGroupList.setAdapter(aGroupList);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
System.out.println("The read failed: " + databaseError.getCode());
}
});
however the problem seems to be that instead of joining the two nodes to show item as one, I am getting two items in the list (first one containing data from lGroupsList and second one from lGroupsList2) they do not seem be joining.
// Joining The Arrays To Get One Array
lGroupsList.addAll(lGroupsList2);