I have created a tableview row.here the tableview each row having the one lebel and 2 image view.if am clicking the image, the selected row of label value need to change something.
But from my code if am clicking the image, the label value is changed of last item. What's wrong in my code.
for( var i=0; i<data.length; i++){
var row = Ti.UI.createTableViewRow({
layout : 'horizontal',
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,
color: '#040404',
height: Ti.UI.SIZE,
}));
var deleteitem = Ti.UI.createImageView({
image: "images/back.png",
top: 5,
i:i,
squantity : data[i].itemCount,
spprice :data[i].itemPrice,
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
myrow: row,
});
row.add(deleteitem);
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,
width: Ti.UI.SIZE,
squantity : data[i].itemCount,
spprice :data[i].itemPrice,
height: Ti.UI.SIZE,
});
adddeleteitemview.add(removeitem);
var itemcounttext = Ti.UI.createLabel({
top: 5,
text:data[i].itemCount,
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
});
adddeleteitemview.add(itemcounttext);
removeitem.addEventListener('click', function(e) {
squantity = e.source.squantity;
spprice = e.source.spprice;
totalqty = Number(totalqty) - Number(1);
$.ViewCartItemslist_header_cart.text = totalqty;
totalamount = Number(totalamount) - Number((spprice));
squantity = Number(squantity) - 1;
itemcounttext.text=squantity;
$.ViewCartItemslist_total_value.text = totalamount;
});
var additem = Ti.UI.createImageView({
image: "images/plus.jpg",
top: 5,
width: Ti.UI.SIZE,
squantity : data[i].itemCount,
spprice :data[i].itemPrice,
height: Ti.UI.SIZE,
});
adddeleteitemview.add(additem);
additem.addEventListener('click', function(e) {
squantity = e.source.squantity;
spprice = e.source.spprice;
totalqty = Number(totalqty) + Number(1);
$.ViewCartItemslist_header_cart.text = totalqty;
totalamount = Number(totalamount) + Number((spprice));
squantity = Number(squantity) + 1;
itemcounttext.text=squantity;
$.ViewCartItemslist_total_value.text = totalamount;
});
row.add(adddeleteitemview);
dataArray.push(row);
row.addEventListener('click', function() {});
deleteitem.addEventListener('click', function(e) {
squantity = e.source.squantity;
spprice = e.source.spprice;
$.ViewCartItemstableView.deleteRow(e.source.myrow);
totalqty = Number(totalqty) - Number(squantity);
$.ViewCartItemslist_header_cart.text = totalqty;
totalamount = Number(totalamount) - Number((spprice * squantity));
$.ViewCartItemslist_total_value.text = totalamount;
});
};
$.ViewCartItemstableView.setData(dataArray);
}
EDIT:
From Tony answer am getting the little bit improvement.,
removeitem.addEventListener("click",function(e){
var item=e.source;
item.getParent();
Ti.API.info("parent"+item.getParent());
});
here am getting the results like :
parent[object TiUIView]
how can i modify the text for
var itemcounttext = Ti.UI.createLabel({
top: 5,
text:data[i].itemCount,
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
});
How can i get this label id value and need to modify the results in the imageview onclick event listener((i.e.,)removeitem.addEventListener("click",function(e){)
If any one knows give me a idea to implementation
EDIT:
From Tony commment.,
It's working well in the IOS.But it's not work with the android implementation.
alert(item.children[1].getText());
Here am getting the alert with correct updated value.But it's not showing in the label. Can you give me a idea to resolve this problem in android.