java - How to sum user input edittext numbers using a for loop -


i have situation, see pic here: user enters quantity cart on add cart button

every time user adds item cart, want store quantity number in arraylist(or list) , display quantity on items textview. if user adds item, arraylist(one first quantity) should increased second quantity , display sum in items textview, computing sum of quantities added.

so, tried using loop,

string quantity_temp = string.valueof(quantitypicker_npkr.gettext().tostring()); int quantity = integer.parseint(quantity_temp);       int total = 0; //declare , initialize arraylist;  (int = 1; < //declaredarralist.size(); i++) {      total = total + quantity;     itemno_txt.settext("  " + total);  } 

i know have declare arraylist hold quantity , give size. stuck, since size of arraylist depends on quantities entered, arraylist has dynamic. how go this.

be gentle, new android. code no perfect

you can create arraylist this

arraylist<youritemclass> items = new arraylist<youritemclass>();  items.add(new youritemclass(...)); items.add(new youritemclass(...)); 

and retrieve data can iterate on

for (youritemclass item : items) {    //use item display } 

if want use string youritemclass can string this

arraylist<string> items = new arraylist<string>();  items.add(new string(...)); items.add(new string(...)); 

and retrieve strings can iterate on

for (string item : items) {    //use item string display } 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -