title: I cannot get sum of the firebase data values in android studio
body: <p>I am making an android app using android studio. I have linked it to firebase Realtime database. I want to retrieve the sum of some child values in one of the activities. This is my json file:-</p>
  <pre><code>{
    &quot;Data&quot; : {
      &quot;UyhzVqsz1BVFKoePa2NEmlPFu382&quot; : {
        &quot;Budget&quot; : {
          &quot;Expanse&quot; : {
            &quot;Wedding&quot; : {
              &quot;stData1&quot; : &quot;W&quot;,
              &quot;stData2&quot; : &quot;Wedding&quot;,
              &quot;stData3&quot; : &quot;111&quot;,
              &quot;stData4&quot; : &quot;11111&quot;
            }
          }
        },
        &quot;Traffic&quot; : {
          &quot;Wedding&quot; : {
            &quot;-MYKeSN8GZ8WbI-8TfVB&quot; : {
              &quot;stData1&quot; : &quot;15 Apr 2021,06:43:00:pm&quot;,
              &quot;stData2&quot; : &quot;Wedding&quot;,
              &quot;stData3&quot; : &quot;kkk&quot;,
              &quot;stData4&quot; : &quot;100&quot;
            },
            &quot;-MYLu2qPmt9qj1tJPkrP&quot; : {
              &quot;stData1&quot; : &quot;16 Apr 2021,00:30:47:am&quot;,
              &quot;stData2&quot; : &quot;Wedding&quot;,
              &quot;stData3&quot; : &quot;ddd&quot;,
              &quot;stData4&quot; : &quot;200&quot;
            }
          }
        }
      }
    }
  }
  </code></pre>
  <p>I have seen many possible solutions to this problem .I applied many of them in my app .But none of the worked. The following code worded a bit. Now the problem is that this code brings the value of the last entered data. I still cannot get the sum of all child nodes.</p>
  <pre><code>   myRef = myfire.getReference().child(&quot;Data&quot;).child(strUID).child(&quot;Traffic&quot;);
  
          myRef.child(&quot;Wedding&quot;).orderByChild(&quot;stData2&quot;).equalTo(&quot;Wedding&quot;).addValueEventListener(new ValueEventListener() {
              @Override
              public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                  for(DataSnapshot data: dataSnapshot.getChildren()) {
                      int sum = 0;
                      String value = data.child(&quot;stData4&quot;).getValue(String.class);
                      assert value != null;
                      int total = Integer.parseInt(value);
  
                      sum= sum + total;
  
                          tvBalance.setText(String.valueOf(sum));
                      }
                  }
  
  
              @Override
              public void onCancelled(@NonNull DatabaseError databaseError) {
  
              }
          });
  
  </code></pre>
  <p>Please give a practical example.</p>