Foreach loop not working in android for custom object -


i trying store count of number of times item list view clicked in custom array list in code quantity of first clicked item increasing , if click on other item gets added list view instead of increasing quantity. please tell me if know other method count.

    listview.setonitemclicklistener(new adapterview.onitemclicklistener() {        @override        public void onitemclick(adapterview<?> parent, view view, int position, long id) {            flowers item = (flowers) parent.getadapter().getitem(position);            if(item == null)            {                toast.maketext(getbasecontext(),"item 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 = 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;                             }                          }                      }                  }        }    }); 

and counter class is

public class counter {   public int cartitemposition;   public int menuitemposition;   public int quantity;} 


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -