java - implementing substraction on listview -


hi new on page.

i developing app, on android, have listview populate list of numbers, in 1 column have value of items. can add them , sum them in variable total, use onitemclick event on listview, in order of delete rows, want delete row value total variable example.

if have values 8 90 3, total 101, if delete value 90 row id 1, how can delete total , set new total 11 new total left substraction.

i implement solution substract on value if put 2 values gave me error here implementation:

 mlistview.setonitemclicklistener(new onitemclicklistener() {          public void onitemclick(adapterview<?> a, view v, int position, long id) {                int k = (int) id;               list<data> dcontrol;              dcontrol = data;                for(data dt: dcontrol){                 residuo = integer.parseint(dt.gety());                }               resultnumber = resultnumber - residuo;               system.out.println(resultnumber);               updatetextfield();                sh.deletecloudprint(data.remove(k));               madapter.notifydatasetchanged();               }           }); 

if adapter looks like:

arrayadapter<string> a2 = new arrayadapter<string>(this,android.r.layout.simple_list_item_1, android.r.id.text1, al); 

then can try this:

listview.setadapter(a2);         listview.setonitemclicklistener(new onitemclicklistener()                                              {                                                 public void onitemclick(adapterview<?> arg0, view arg1, int arg2, long arg3)                                                  {                                                     string s1;                                                     s1 = (string) ((textview)arg1).gettext();                                                      int value = integer.parseint(s1);                                                      total = total - value;                                                 }                                              }                                         ); 

hope code works you.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -