imageview - Label text is not updating in tableview children in titanium android.but work's in IOS -
i have tried update/change lebel in android using titanium.but value not showing on text .but getting updated value in alert.but ios working perfectly.
var itemcounttext = ti.ui.createlabel({ top: 5, color: "#000000", left:10, text:data[i].itemcount, width: ti.ui.size, height: ti.ui.size, }); var additem = ti.ui.createimageview({ image: "/images/plus.jpg", top: 5, width: ti.ui.size, left:10, height: ti.ui.size, }); adddeleteitemview.add(additem); additem.addeventlistener('click', function(e) { var item=e.source.getparent(); squantity = e.source.squantity; squantity = number(squantity) + 1; item.children[1].text = squantity; alert(item.children[1].gettext());
here getting alert correct updated value.but it's not showing in label. can give me idea resolve problem in android.
edit:
from vrk comment have tried also.but it's not working.but getting alert correctly.
item.children[1].settext(squantity);
edit:
i tried jsplaine answer.but can't solution. here have created tableview .in tableview row creating view.in view have adidng additem,itemcounttext values.if clicking additem means need change itemcounttext value.this flow.
like below screenshot children view of app tableview:
productname remove itemcount add image text image
this 3 image,text,image values added in 1 view.that's why adding code getting parent view while clicking add image:
var item=e.source.getparent();
here getting parent.also wrote below code getting label view:
item.children[1].text
if clicking add image, getting label value incresed 1 correctly .am verified code alert(item.children[1].gettext())
;. updated value not showing.this exact doubt.
edit:
this full source code.
dataarray = []; $.viewcartitemslist_total_value.text = totalamount; for( var i=0; i<data.length; i++){
//creating tableviewrow
var row = ti.ui.createtableviewrow({ layout : 'horizontal', top:5, width: "100%", height: ti.ui.size, }); row.add(ti.ui.createimageview({ image: data[i].image, top: 5, width: '50', height: ti.ui.size, })); row.add(ti.ui.createlabel({ text: data[i].name, top: 5, width: 180, font: { fontsize: '10dp' }, color: '#040404', wordwrap: true, height: ti.ui.size, ellipsize: true }));
//creating view inside of each every row of tableviewrow
var adddeleteitemview = ti.ui.createview({ width: ti.ui.size, height: ti.ui.size, layout : 'horizontal', left:10, bordercolor:"gray", borderradius:"10" }); var removeitem = ti.ui.createimageview({ image: "/images/minus.jpg", top: 5, left:10, width: "15%", height: ti.ui.size, }); adddeleteitemview.add(removeitem); var itemcounttext = ti.ui.createlabel({ top: 5, color: "#000000", left:10, text:data[i].itemcount, textalign:'center', width: "15%", height: ti.ui.size, }); adddeleteitemview.add(itemcounttext); var additem = ti.ui.createimageview({ image: "/images/plus.jpg", top: 5, width: "15%", left:10, squantity : data[i].itemcount, spprice :data[i].itemprice, height: ti.ui.size, }); adddeleteitemview.add(additem); additem.addeventlistener('click', function(e) { var item=e.source.getparent(); spprice = e.source.spprice; if(item.children[1].gettext() == e.source.squantity){ squantity = e.source.squantity; totalqty = number(totalqty) + number(1); $.viewcartitemslist_header_cart.text = totalqty; totalamount = number(totalamount) + number((spprice)); squantity = number(squantity) + 1; item.children[1].text = squantity; // item.itemcounttext.text = squantity; // item.itemcounttext.settext(squantity); // item.children[1].settext(squantity); alert(item.children[1]+" "+item.children[1].gettext()); $.viewcartitemslist_total_value.text = totalamount; totalprice = number(spprice) * squantity; } else { squantity = item.children[1].gettext(); totalqty = number(totalqty) + number(1); $.viewcartitemslist_header_cart.text = totalqty; totalamount = number(totalamount) + number((spprice)); squantity = number(squantity) + 1; item.children[1].text = squantity; item.children[1].settext(squantity); alert(item.children[1].gettext()); $.viewcartitemslist_total_value.text = totalamount; totalprice = number(spprice) * squantity; } }); row.add(adddeleteitemview); dataarray.push(row); row.addeventlistener('click', function(e) { }); $.viewcartitemstableview.setdata(dataarray); }
instead of walking parent/child tree, make itemcounttext property of additem:
var itemcounttext = ti.ui.createlabel({ top: 5, color: "#000000", left:10, text:data[i].itemcount, width: ti.ui.size, height: ti.ui.size }); var additem = ti.ui.createimageview({ image: "/images/plus.jpg", top: 5, width: ti.ui.size, left:10, height: ti.ui.size, }); additem.counttextlabel = itemcounttext; adddeleteitemview.add(additem); additem.addeventlistener('click', function(e) { var item=e.source; var squantity = e.source.squantity; squantity = number(squantity) + 1; item.counttextlabel.settext(squantity); alert(item.counttextlabel.gettext()); });
Comments
Post a Comment