title: Android + Sum up values of a parse query
body: <p>I have the following problem:
  I want to sum up the ratings (coloumn “Rating”) and later calculate an average rating. 
  Unfortunately this doesn’t work, and it seems to me that the problem lies with or within the foreach loop. The variable avg has no value after the loop and i don't see the reason for this.
  Thank you very much for your help.</p>
  
  <p>Table "RateAndComment"
  <a href="http://www.directupload.net/file/d/3831/y23ygngp_png.htm" rel="nofollow">http://www.directupload.net/file/d/3831/y23ygngp_png.htm</a></p>
  
  <pre><code>    protected double totalRating;
      protected int i;
      protected float avg;
  
  public void CalculateRating(String objectId)
      {
  
  
          //ParseQuery&lt;ParseObject&gt; query = ParseQuery.getQuery("RateAndComment");
          ParseQuery query = new ParseQuery("RateAndComment");
          query.whereEqualTo("PlaceObjectId",objectId);
          query.findInBackground(new FindCallback&lt;ParseObject&gt;() {
                                     @Override
                                     public void done(List&lt;ParseObject&gt;list,
                                      com.parse.ParseException e) {
                                         if (e == null) {
                                             i=0;
                                             for (ParseObject obj : list) {
                                                 totalRating = totalRating + obj.getDouble("Rating");
                                                 i = i + 1;
                                             }
                                         } else {
                                             Log.d("Post retrieval", "Error: " + e.getMessage());
                                         }
                                     }
  
                                 }
          );
          avg = (float) totalRating/i;
          avgRating(objectId);
      }
  </code></pre>