I have a class Java
that I overwritten the toString()
method inside this method before returning I consult the fireBase and fill in an object. My problem is the return
of toString()
ends up running before the firebase has filled the object. How can I tell the class to wait for the object to be filled before it returns
public class exom(){
private String ID;
private String horaInicio;
private String horaFim;
private String IDEvento;
// Objeto que deve vir do firebase
Objeto obj;
//Getters and setters....
@Override
public String toString() {
FireDB fireDB = new FireDB(null);
fireDB.getMdatabase().addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot child : dataSnapshot.getChildren()) {
obj = child.getValue(Objeto.class);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
return horaInicio + " - " + horaFim + " - "+ obj.getNome();
}
}