public ArrayList< Event > getAllEventsOnFirebase(final EventListAdapter adapter,
final ArrayList<Event> events) {
DatabaseReference eventsTable = getDatabaseTableWith(Constants.tableEvents);
eventsTable.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot postSnapshot: dataSnapshot.getChildren()) {
String eventId = postSnapshot.child(Constants.taEventUUID).getValue(String.class);
String eventName = event.child(Constants.taEventName).getValue(String.class);
String eventAddress = event.child(Constants.taEventAddress).getValue(String.class);
Event newEvent = new Event(eventId, eventName, eventAddress);
events.add(newEvent);
}
adapter.notifyDataSetChanged();
}
@Override
public void onCancelled(DatabaseError databaseError) {
throw databaseError.toException();
}
});
}
//call with
ArrayList< Event > events = new ArrayList<Event>();
EventListAdapter adapter = new EventListAdapter(this, eventsArray);
eventsListView.setAdapter(adapter);
FirebaseConnection.getInstance().getAllEventsOnFirebase(adapter, events);