android - Change TextView on Button Click -


i working on shopping cart app. in there plus , minus button adding items in cart.

if user clicks on plus button there textview should change 0 1 or more same things should done if user click on minus button value of textview should decrease.

i changed value increase , decrease more 1 row @ once.

@suppresslint("inflateparams") public class productlistadapter extends baseadapter {     private activity activity;     private layoutinflater inflater;     private list<product> products;     private productlistadapterlistener listener;     int t;     int count = 0;     context context;     list<product> rowitems;     string[] result;     viewholder holder;      protected static final string tag = "reviewadapter";     imageloader imageloader = appcontroller.getinstance().getimageloader();     private hashmap<integer, integer> mcounthash;      public productlistadapter(activity activity, list<product> feeditems,             productlistadapterlistener listener) {         this.activity = activity;         this.products = feeditems;         this.listener = listener;     }      public static class viewholder {         textview name, description, price, qty;         button btnaddtocart, btnreduce;         networkimageview image;     }      @override     public int getcount() {         return products.size();     }      @override     public object getitem(int location) {         return products.get(location);     }      @override     public int getitemviewtype(int position) {         // todo auto-generated method stub         return position;     }      @override     public long getitemid(int position) {         // todo auto-generated method stub         return position;     }      @suppresslint("viewholder")     @override     public view getview(final int position, view convertview, viewgroup parent) {          if (inflater == null)             inflater = (layoutinflater) activity                     .getsystemservice(context.layout_inflater_service);         resources resources = this.context.getresources();         if (convertview == null)             convertview = inflater.inflate(r.layout.list_item_product, null);         final view vii = convertview;          final product product = products.get(position);         holder = new viewholder();          holder.name = (textview) convertview.findviewbyid(r.id.productname);         holder.description = (textview) convertview                 .findviewbyid(r.id.productdescription);         holder.qty = (textview) convertview.findviewbyid(r.id.productqty);          holder.price = (textview) convertview.findviewbyid(r.id.productprice);         holder.image = (networkimageview) convertview                 .findviewbyid(r.id.productimage);          // holder.qty=(textview) convertview.findviewbyid(r.id.productqty);         holder.btnaddtocart = (button) convertview                 .findviewbyid(r.id.btnaddtocart);         holder.btnreduce = (button) convertview.findviewbyid(r.id.btnreduce);          holder.name.settext(product.getname());         holder.description.settext(product.getdescription());         holder.price.settext("$" + product.getprice());         // user profile pic          holder.image.setimageurl("http://flavorbaba.com/adminpanel/images/"                 + product.getimage(), imageloader);          holder.btnaddtocart.settag(position);         holder.qty.settag(position);         holder.btnaddtocart.settag(holder);         // holder.btnreduce.setenabled(false);          // holder.btnreduce.setvisibility(view.gone));         holder.btnaddtocart.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                 count++;                  listener.onaddtocartpressed(product);                  view parentview = (view) vii.getparent();                 // textview tvqty = ((textview) parentview                 // .findviewbyid(r.id.textview1)).gettext().tostring();                 textview tvqty = ((textview) parentview                         .findviewbyid(r.id.productqty));                 tvqty.settext(string.valueof(count));                 // button btnaddtocart = (button) v;                  // holder.qty.settext(string.valueof(count));                 // notifydatasetchanged();                  toast.maketext(activity, string.valueof(position),                         toast.length_short).show();             }          });          holder.btnreduce.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view v) {                  // t = integer.parseint(holder.qty.gettext().tostring());                 // holder.qty.settext(string.valueof(t - 1));                  listener.onreducepressed(product);             }         });         convertview.settag(holder);          return convertview;     }      public interface productlistadapterlistener {         public void onaddtocartpressed(product product);          public void onreducepressed(product product);     }  } 

hope code may you.

plus = (button) findviewbyid(r.id.btn_plus);     minus = (button) findviewbyid(r.id.btn_minus);      plus.setonclicklistener(new onclicklistener() {          @override         public void onclick(view v)          {             // todo auto-generated method stub             txt_number.settext(integer.tostring(textvalue));             textvalue++;         }     });      minus.setonclicklistener(new onclicklistener() {          @override         public void onclick(view v) {             // todo auto-generated method stub             textvalue--;             txt_number.settext(integer.tostring(textvalue));         }     }); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -