I was trying to take the all the key values as String and add them to "studentrolls" Arraylist and trying to return the Arraylist so that I can make Multiple choice Dialog box. But somehow its not adding to any element to the arraylist. Here's my code:
public ArrayList < String > getAllstudents(String coursename) {
rootnode = FirebaseDatabase.getInstance();
String uniqueid = coursename + ID;
reference = rootnode.getReference().child("Course").child(uniqueid).child("students");
studentrolls = new ArrayList < String > ();
Log.d(TAG, "Teachers ID: " + ID);
reference.addValueEventListener(new ValueEventListener() {
@SuppressLint("LongLogTag")@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
Log.d(TAG, "onDataChange: " + snapshot + "");
Log.d(TAG, "onDataChange: " + snapshot.getValue() + "");
Log.d(TAG, "Checking snapshot: " + snapshot.getChildren().toString());
for (DataSnapshot ds: snapshot.getChildren()) {
Log.d(TAG, "Students roll: " + "" + ds.getKey());
Log.d(TAG, "Data type" + ds.getKey().getClass().getName());
studentrolls.add(ds.getKey());
//Log.d(TAG, "Teachers ID from firebase: " + teID);
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
Log.d(TAG, "Fetching data was failed");
}
});
Log.d(TAG, "Inside mydatabae helper array list=====" + studentrolls.size());;
return studentrolls;
}