title: Foreach loop not working in android for custom object
body: <p>I am trying to store the count of number of times an item from a list view is clicked  in a custom array list but in my code the quantity of only the first clicked item is increasing and if i click on any other item then it gets added to the list view instead of increasing the quantity. Please tell me if you know any other method to get the count. Thanks </p>
  
  <pre><code>    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
         @Override
         public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
             Flowers item = (Flowers) parent.getAdapter().getItem(position);
             if(item == null)
             {
                 Toast.makeText(getBaseContext(),"item is null",Toast.LENGTH_LONG).show();
             }else {
  
                      selectedItems items = new selectedItems();
                      items.setName(item.getName());
                      items.setCategory(item.getCategory());
                      Counter counter = new Counter();
                      if(selectedItemsArrayList.isEmpty())
                      {
  
                          counter.CartItemPosition = 0;
                          counter.MenuItemPosition = position;
                          counter.quantity = 1;
                          items.setQuantity(counter.quantity);
                          count.add(counter);
                          selectedItemsArrayList.add(items);
  
                      }
                 else
                      {
                          for(Counter c : count)
                          {
                              if(c.MenuItemPosition == position)
                              {
                                  c.quantity = c.quantity + 1;
                                  int i = c.CartItemPosition;
                                  selectedItemsArrayList.get(i).setQuantity(c.quantity);
                                  break;
                              }
                              else
                              {
                                  Counter obj = new Counter();
                                  obj.MenuItemPosition = position;
                                  obj.CartItemPosition++;
                                  obj.quantity=1;
                                  count.add(obj);
                                  items.setQuantity(obj.quantity);
                                  selectedItemsArrayList.add(items);
                                  return;
                              }
  
                          }
  
                      }
  
  
                 }
         }
     });
  </code></pre>
  
  <p>and my Counter class is</p>
  
  <pre><code>public class Counter {
    public int CartItemPosition;
    public int MenuItemPosition;
    public int quantity;}
  </code></pre>