Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Label text is not updating in tableview children in titanium android.but work's in IOS

I have tried to update/change the lebel in android using titanium.but the value is not showing on the text .but am getting the updated value in the alert.But the ios is 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 am getting the alert with correct updated value.But the it's not showing in the label. Can you give me a idea to resolve this problem in android.

EDIT:

From VRK comment i have tried this also.But it's not working.but am getting the alert correctly.

item.children[1].setText(squantity);

EDIT:

I tried with jsplaine answer.But i can't get the solution. Here i have created the tableview .in this tableview row we are creating the view.in that view i have adidng the additem,itemcounttext values.if we are clicking the additem means need to change the itemcounttext value.This is a flow.

like below screenshot is children view of my app tableview:

productname

remove     itemcount   add
image      text        image

this three image,text,image values are added in one view.That's why am adding the code for getting the parent view while clicking add image:

var item=e.source.getParent();

here am getting the parent.also am wrote the below code for getting the label for this view:

item.children[1].text

If am clicking the add image, am getting the label value is incresed by 1 correctly .am verified with this code alert(item.children[1].getText());. but the updated value is not showing.This is my exact doubt.

EDIT:

This is my full source code.

 dataArray = [];       
 $.ViewCartItemslist_total_value.text = totalamount;
 for( var i=0; i<data.length; i++){ 

//creating the 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 the 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);
     }
like image 858
Krishna Veni Avatar asked May 14 '15 07:05

Krishna Veni


1 Answers

Instead of walking the parent/child tree, just make itemcounttext a 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());
});
like image 101
jsplaine Avatar answered Oct 18 '22 19:10

jsplaine