text: Q:
  
  How to sum multiple values from firebase
  
  I'm new at android programming as well as firebase. first of all look at the picture 
  Details image
  
  In there I want to get all the "cost" part in total(sum). I've created the reference like that 
  DatabaseReference databaseBazars=firebaseDatabase.getInstance().getReference("BazarList");
  
  now what procedure I can follow to get sum and show it in list view or in a toast message).
  I've done this to get all the data from that(BazarList) node . and it perfectly showing on the listview. 
  
    databaseBazars.addValueEventListener(new ValueEventListener() {
  
              @Override
              public void onDataChange(DataSnapshot dataSnapshot) {
  
                   bazarList.clear();
                   for( DataSnapshot ds :dataSnapshot.getChildren()) {
                       Bazar bazar = ds.getValue(Bazar.class);
                       bazarList.add(bazar);
                   }
              BazarList adapter = new BazarList(Bazar_Data_Input.this,bazarList);
                  listViewBazars.setAdapter(adapter);
              }
  
              @Override
              public void onCancelled(DatabaseError databaseError) {
  
              }
          });
  
  now, how can I get the sum part of the cost. anyone, please help me
  here is the Bazar Class 
  public class Bazar {
      String bid;
      String date;
      String cost;
      String name;
      String item;
  
      public Bazar(){
  
      }
  
      public Bazar(String bid, String date, String cost, String name,String item) {
          this.bid = bid;
          this.date = date;
          this.cost = cost;
          this.name = name;
          this.item= item;
      }
  
      public String getBid() {
          return bid;
      }
  
      public String getDate() {
          return date;
      }
  
      public String getCost() {
          return cost;
      }
  
      public String getName() {
          return name;
      }
  
      public String getItem() {
          return item;
      }
  }
  
  A:
  
  To solve this, please use the following code:
  databaseBazars.addValueEventListener(new ValueEventListener() {
      @Override
      public void onDataChange(DataSnapshot dataSnapshot) {
          bazarList.clear();
          Integer total = 0;
  
          for( DataSnapshot ds :dataSnapshot.getChildren()) {
              Bazar bazar = ds.getValue(Bazar.class);
              Integer cost = Integer.valueOf(bazar.getCost());
              total = total + cost;
              bazarList.add(bazar);
          }
          BazarList adapter = new BazarList(Bazar_Data_Input.this,bazarList);
          listViewBazars.setAdapter(adapter);
          Log.d("TAG", total + "");
      }
  
      @Override
      public void onCancelled(DatabaseError databaseError) {}
  });
  
  The output will be: 59512.
  
  