android - How to get all values from text view of custom list view -
i want values of text view list view. how can it. have list view , put array list in list view. list view custom list view. want data price text view , want show total of price . , code give error
it's code.
public class selectedproductfromshopingcartshow extends appcompatactivity { arraylist<showproducts> arraylist = new arraylist<>(); string condition = "selecteditemsfromshoppingcart"; customadapter customadapter; listview listview; textview tvtotal; int total; private static final string tag = "selectedproductfromshop"; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_selected_product_from_shoping_cart_show); listview = (listview) findviewbyid(r.id.listviewselecteditemsofshopingcart); tvtotal = (textview) findviewbyid(r.id.tvtotal); arraylist = (arraylist<showproducts>) getintent().getserializableextra("selectedlist"); customadapter = new customadapter(selectedproductfromshopingcartshow.this, r.layout.show_selected_item_of_shopingcart, condition, arraylist); listview.setadapter(customadapter); total = gettotal(listview); tvtotal.settext(string.valueof(total).tostring()); } public int gettotal(listview listview) { int sum = 0; (int = 0; < listview.getcount(); i++) { log.d(tag, "gettotal: "+listview.getcount()); log.d(tag, "gettotal: "+arraylist.size()); view view = listview.getchildat(i); textview tvprice = (textview) view.findviewbyid(r.id.tvsetpriceofseleteditem); textview tvquantity = (textview) view.findviewbyid(r.id.tvqunatitysetofselecteditem); int price = integer.parseint(tvprice.gettext().tostring()); int quantity = integer.parseint(tvquantity.gettext().tostring()); sum = sum + price * quantity; } return sum; } } and it's error. don't know how can it. please me.
07-26 18:03:49.404 21155-21155/com.sizdom.sizdomstockmanager e/androidruntime: fatal exception: main java.lang.runtimeexception: unable start activity componentinfo{com.sizdom.sizdomstockmanager/com.sizdom.sizdomstockmanager.selectedproductfromshopingcartshow}: java.lang.nullpointerexception @ android.app.activitythread.performlaunchactivity(activitythread.java:2204) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2254) @ android.app.activitythread.access$600(activitythread.java:141) @ android.app.activitythread$h.handlemessage(activitythread.java:1234) @ android.os.handler.dispatchmessage(handler.java:99) @ android.os.looper.loop(looper.java:137) @ android.app.activitythread.main(activitythread.java:5069) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:511) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) @ dalvik.system.nativestart.main(native method) caused by: java.lang.nullpointerexception @ com.sizdom.sizdomstockmanager.selectedproductfromshopingcartshow.gettotal(selectedproductfromshopingcartshow.java:88) @ com.sizdom.sizdomstockmanager.selectedproductfromshopingcartshow.oncreate(selectedproductfromshopingcartshow.java:38) @ android.app.activity.performcreate(activity.java:5104) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1092) @ android.app.activitythread.performlaunchactivity(activitythread.java:2148) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2254) @ android.app.activitythread.access$600(activitythread.java:141) @ android.app.activitythread$h.handlemessage(activitythread.java:1234) @ android.os.handler.dispatchmessage(handler.java:99) @ android.os.looper.loop(looper.java:137) @ android.app.activitythread.main(activitythread.java:5069) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:511) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) @ dalvik.system.nativestart.main(native method) i check out multiple sites solutions. don't find soluotion
custom adapter
public class customadapter extends arrayadapter { private list<integer> list; private list<showproducts> listshowproducts; private context context; private int resource; private string condition; string uri; private static final string tag = "customadapter"; int = 0; public customadapter(@nonnull context context, @layoutres int resource, list<showproducts> objects) { super(context, resource, objects); this.context = context; this.resource = resource; this.listshowproducts = objects; } @override public int getcount() { return super.getcount(); } @nullable @override public object getitem(int position) { return super.getitem(position); } @nonnull @override public view getview(int position, @nullable view convertview, @nonnull viewgroup parent) { view view = layoutinflater.from(context).inflate(resource, parent, false); final showproducts showproducts = listshowproducts.get(position); imageview imageview = (imageview) view.findviewbyid(r.id.imageviewofselecteditem); imageview plus = (imageview) view.findviewbyid(r.id.imageviewplus); imageview minus = (imageview) view.findviewbyid(r.id.imageviewminus); textview tvsetnameofseleteditem = (textview) view.findviewbyid(r.id.tvsetnameofseleteditem); textview tvsetsizeofseleteditem = (textview) view.findviewbyid(r.id.tvsetsizeofseleteditem); textview tvsetpriceofseleteditem = (textview) view.findviewbyid(r.id.tvsetpriceofseleteditem); final textview tvqunatitysetofselecteditem = (textview) view.findviewbyid(r.id.tvqunatitysetofselecteditem); tvsetnameofseleteditem.settext(showproducts.getproduct_name().tostring()); tvsetsizeofseleteditem.settext(showproducts.getsize_name()); tvsetpriceofseleteditem.settext(string.valueof(showproducts.getsize_price()).tostring()); uri = showproducts.getproduct_photo().tostring(); picasso.with(context).load(uri).into(imageview); plus.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { int a=integer.parseint(tvqunatitysetofselecteditem.gettext().tostring()); a++; if (a<=showproducts.getsize_quantity()) tvqunatitysetofselecteditem.settext(string.valueof(a).tostring()); } }); minus.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { int a=integer.parseint(tvqunatitysetofselecteditem.gettext().tostring()); a--; if (a>0) tvqunatitysetofselecteditem.settext(string.valueof(a).tostring()); } }); } return view; } } it's list view show value when value arror
i debug app
public int gettotal(listview listview) { int sum = 0; (int = 0; < listview.getcount(); i++) { // i=0; log.d(tag, "gettotal: "+listview.getcount()); log.d(tag, "gettotal: "+arraylist.size()); // arraylist=4; view view = listview.getchildat(i); //view=null; textview tvprice = (textview) view.findviewbyid(r.id.tvsetpriceofseleteditem); log.d(tag, "gettotal: "+tvprice.gettext()); textview tvquantity = (textview) view.findviewbyid(r.id.tvqunatitysetofselecteditem);
you not setting price in tvprice , quantity in tvquantity textview. null value.

Comments
Post a Comment