title: How to listen for changes in android studio using firebase
body: <p>I am having a hard time reading changes on my firebase. What I am trying to do is for every change when the start button is triggered a dialog will show saying, "This has already been executed." </p>
  
  <p>I tried using addListenerForSingleValueEvent but it seems that the dialog only showed when all of the children have changed. </p>
  
  <pre><code> startBtn.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              currentWeek = programTrackers.get(0).getWeek();
              DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("ProgramTracker")
                      .child(GlobalUser.getmUser().getiD())
                      .child(programTrackers.get(0).getProgramId());
              databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
                  @Override
                  public void onDataChange(DataSnapshot dataSnapshot) {
                      final int childCount = (int) dataSnapshot.getChildrenCount();
                      int count = 0;
                      for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                          ProgramTracker programTracker = snapshot.getValue(ProgramTracker.class);
                          if (programTracker.getProgramExerciseWeek() == currentWeek) {
                              programTrackChecker.add(programTracker);
  
  
                          }
                          count++;
                      }
                      if (count == childCount) {
                          boolean isFinished = false;
                          //last iteration
                          for (int i = 0; i &lt; programTrackChecker.size(); i++) {
                              if (programTrackChecker.get(i).isProgramExerciseFinished()) {
                                  isFinished = true;
                              } else
                                  isFinished = false;
                          }
                          if (isFinished) {
                              AlertDialog.Builder builder = new AlertDialog.Builder(DayExerciseActivity.this);
                              builder.setMessage("You have already completed all exercises. Are you sure you want to do it again?");
                              builder.setPositiveButton("Yes", (dialogInterface, i) -&gt; {
                                  startActivity(new Intent(DayExerciseActivity.this, DoProgramActivity.class)
                                          .putExtra("programTrackers", programTrackers)
                                          .putExtra("exerciseNum", String.valueOf(0)));
  
                              });
                              builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                                  @Override
                                  public void onClick(DialogInterface dialogInterface, int i) {
                                      dialogInterface.dismiss();
                                  }
                              });
                              builder.show();
  
  
                          } else
                              startActivity(new Intent(DayExerciseActivity.this, DoProgramActivity.class)
                                      .putExtra("programTrackers", programTrackers)
                                      .putExtra("exerciseNum", String.valueOf(0)));
  
                      }
  
                  }
  
                  @Override
                  public void onCancelled(DatabaseError databaseError) {
  
                  }
              });
  </code></pre>