I'm developing an app and in database there are users like doctor and patient. There may be doctors userId in patient datas and patient userId
in doctor datas. Because in app doctor will see some information about his/her patient. I develop this chunk of codes, but I could not add patient informations to Arraylists before setting adapter. Here is my codes:
myRef.child("users")
.child(firebaseUser.getUid()).child("patients").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot ds: dataSnapshot.getChildren()){
AddingPatients addingpatient = ds.getValue(AddingPatients.class);
if(addingpatient.getConfirm().equals("yes")){
myref.child("users").child(addingpatient.getUserId()).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
Users patient = dataSnapshot.getValue(Users.class);
name.add(patient.getName()+" "+patient.getSurname());
sicks.add(patient.getSicks());
patientuid.add(patient.getUserId());
}
}
@Override
public void onCancelled(DatabaseError error) {
}
});
}
}
PatientSelectionAdapter adapter= new PatientSelectionAdapter(getContext(),name,sicks,hastauid);
rv.setAdapter(adapter);
rv.setLayoutManager(new LinearLayoutManager(getContext()));
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
When I debug codes I saw that, patient information is adding to lists after setting adapter. So my RecyclerView
is empty. How can i fix that problem?