title: Firebase (Android) - Loading filtered data into custom ArrayList
body: <p>Can someone please advice me on this issue:
  I am trying to load some filtered data from Firebase DB onCreate and populate a custom array with data.</p>
  
  <p>After doing some debugging I can tell that the data is loaded from DB but my custom array is not getting populated.</p>
  
  <p>Please have a look at my code below.</p>
  
  <p>Even though my loadAllBooks() method is populating the array, it gets completed too late and the line:</p>
  
  <pre><code>//3) Create the adapter 
  BooksAdapter  adapter = new BooksAdapter  (this, booksList);
  </code></pre>
  
  <p>is executed before loadAllBooks() is completed which results in an empty list...
  It's as if i need some sort of onComple for the addChildEventListener...</p>
  
  <p>Please Help, if more information is needed let me know, thank you:</p>
  
  <pre><code>ArrayList&lt;BookItem&gt; booksList;
  ListView listView;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      //1) empty books list
      booksList = new ArrayList&lt;BookItem&gt;();
  
      //2) load all books from firebase DB - into booksList array
      loadAllBooks();
  
      //3) Create the adapter 
      BooksAdapter  adapter = new BooksAdapter  (this, booksList);
  
      //4) Attach the adapter to a ListView
      listView = (ListView) findViewById(R.id.lvBooks);
      listView.setAdapter(adapter);
  }
  
  public void loadAllBooks() {
      Firebase ref = new Firebase(".......firebaseio.com/books");
      Query queryRef = ref.orderByChild("bookType").equalTo("drama");
      queryRef.addChildEventListener(childEventListener);
  }
  
  ChildEventListener childEventListener  = new ChildEventListener() {
      @Override
      public void onChildAdded (DataSnapshot bookNode, String previousChild){
          BookItem bookItemModel = bookNode.getValue(BookItem.class);
          booksList.add(bookItemModel);
      }
  
      public void onChildRemoved(DataSnapshot snapshot) {}
  
      public void onChildChanged(DataSnapshot snapshot, String previousChild){}
  
      public void onChildMoved(DataSnapshot snapshot, String previousChild) {}
  
      @Override
      public void onCancelled(FirebaseError firebaseError) {}
  };
  </code></pre>
  
  <p>Thank you!</p>