title: Is there a way to count number of children in firebase database?
body: <pre><code>    mImageLike.setOnClickListener(new View.OnClickListener()
      {
          @Override
          public void onClick(View v)
          {
              mProcessLike = true;
              //mLikeCount.setText("numLikes");
              mDatabaseLike.addValueEventListener(new ValueEventListener()
              {
                  @Override
                  public void onDataChange(DataSnapshot dataSnapshot)
                  {
                      if(mProcessLike)
                      {
                          if(dataSnapshot.child(post_key).hasChild(mAuth.getCurrentUser().getUid()))
                          {
                              mDatabaseLike.child(post_key).child(mAuth.getCurrentUser().getUid()).removeValue();
                              numLike--;
                              mProcessLike = false;
                          }
                          else
                          {
                              mDatabaseLike.child(post_key).child(mAuth.getCurrentUser().getUid()).setValue("Liked");
                              mProcessLike = false;
                          }
                      }
                  }
  
                  @Override
                  public void onCancelled(DatabaseError databaseError)
                  {
  
                  }
              });
  
              mDatabaseLike.addChildEventListener(new ChildEventListener()
              {
                  @Override
                  public void onChildAdded(DataSnapshot dataSnapshot, String s)
                  {
                      numLike = dataSnapshot.getChildrenCount();
                      mDatabaseLike.child(post_key).child("numLike").setValue(numLike);
                  }
  
                  @Override
                  public void onChildChanged(DataSnapshot dataSnapshot, String s)
                  {
                  }
  
                  @Override
                  public void onChildRemoved(DataSnapshot dataSnapshot)
                  {
                  }
  
                  @Override
                  public void onChildMoved(DataSnapshot dataSnapshot, String s)
                  {
  
                  }
  
                  @Override
                  public void onCancelled(DatabaseError databaseError)
                  {
  
                  }
              });
          }
      });
  </code></pre>
  
  <p>I was struggling with increasing count when like button is pressed and store that count number into the database "Like". I have declared DatabaseReference mDatabaseLike and it looks like this. <a href="https://i.stack.imgur.com/sxYqn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sxYqn.png" alt="mDatabaseLike"></a></p>
  
  <p>I am trying to count the number of children in each like(the ones with "Liked" string) and store them into each key(ex. Kb6cSLImN_7lrPyAr2Q) as numLike. When I click like button, it updates the count, but when I click the button again to remove that like, the number doesn't decrease. </p>
  
  <p>Please help!. Thank you very much.</p>