I'm trying to retrieve parent node which is group names like Android11 or The lovers based on the value of child node "userID" if match current logged user.
I initialized arraylist and arrayadapter then looped through datasnapashot using Query. So if order by "userID" match the current user then pass the value of parent group name to arraylist "list_of_group" but I get empty list. What do you think the issue is?
private void InitializeFields() {
list_view = (ListView) GroupFragmentView.findViewById(R.id.list_view);
arrayAdapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, list_of_groups);
list_view.setAdapter(arrayAdapter);
}
private void RetriveAndDisplayGroups() {
mAuth = FirebaseAuth.getInstance();
currentUserID = mAuth.getCurrentUser().getUid();
groupList = FirebaseDatabase.getInstance().getReference().child("Group Members");
groupList.orderByChild("userID").equalTo(currentUserID)
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot)
{
list_of_groups.clear();
if (dataSnapshot.exists()) {
for (DataSnapshot ds : dataSnapshot.getChildren())
{
String grpName = ds.getValue().toString();
list_of_groups.add(grpName);
}
arrayAdapter.notifyDataSetChanged();
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
;
});
}