java - How to update the TextView in the activity by clicking a button in ListView? -


here have listview of products. want update totalbill textview, in activity not in listview, whenever user clicks on add button in listview. problem is, customadapter doesn't allow update textview, in activity class, on button click. how achieve this?

        tvid = (textview) v.findviewbyid(r.id.itemid);         tvname = (textview) v.findviewbyid(r.id.itemname);         tvprice = (textview) v.findviewbyid(r.id.itemprice);         tvqty = (textview) v.findviewbyid(r.id.quantity);         plusbutton = (imagebutton) v.findviewbyid(r.id.addbutton);         minusbutton = (imagebutton) v.findviewbyid(r.id.minusbutton);     }     plusbutton.setonclicklistener(new onclicklistener() {          @override         public void onclick(view v) {             int qty = integer.parseint(tvqty.gettext().tostring());             double itemprice=double.parsedouble(tvprice.gettext().tostring());             tvqty.settext(string.valueof(++qty));             shoppingcart2 cart=new shoppingcart2();             cart.addquantity(qty, itemprice);         }     }); 

the above code in customadapter , below in activity class.

    public void addquantity(int quantity, double itemprice) {     try {         double totalprice = quantity * itemprice;         totalbill = totalbill.add(bigdecimal.valueof(totalprice));         totalbill = totalbill.setscale(0, bigdecimal.round_half_up);         tvtotalbill = (textview) findviewbyid(r.id.tvtotalbill);         tvtotalbill.settext(totalbill.tostring());     } catch (exception e) {         e.printstacktrace();     } } 

i getting nullpointer exception in addquantity function. there other way done.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -