标签文本没有更新在woodview中的tableview子项中.但在IOS中工作

Kri*_*eni 14 android label titanium tableview imageview

我试图使用titanium更新/更改android中的lebel.但是文本中没有显示该值.但是我在alert中获得了更新的值.但是ios工作正常.

 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());
Run Code Online (Sandbox Code Playgroud)

这里正在获取具有正确更新值的警报.但它没有显示在标签中.你能给我一个想法来解决android中的这个问题.

编辑:

从VRK评论我也试过了.但它没有工作.但我正确地得到警报.

item.children[1].setText(squantity);
Run Code Online (Sandbox Code Playgroud)

编辑:

我尝试用jsplaine回答.但我无法得到解决方案.在这里我创建了tableview.在这个tableview行中我们创建了view.in该视图我已经添加了additem,itemcounttext值.如果我们点击additem意味着需要更改itemcounttext值.这是一个流程.

如下面的截图是我的app tableview的子视图:

productname

remove     itemcount   add
image      text        image
Run Code Online (Sandbox Code Playgroud)

这三个图像,文本,图像值都添加到一个视图中.这就是为什么在单击添加图像时添加用于获取父视图的代码:

var item=e.source.getParent();
Run Code Online (Sandbox Code Playgroud)

这里得到了parent.also我写了下面的代码来获取这个视图的标签:

item.children[1].text
Run Code Online (Sandbox Code Playgroud)

如果单击添加图像,则正确地将标签值增加1.使用此代码验证.am alert(item.children[1].getText()); 但是没有显示更新的值.这是我的确切怀疑.

编辑:

这是我的完整源代码.

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

//创建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
 }));
Run Code Online (Sandbox Code Playgroud)

//在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);
     }
Run Code Online (Sandbox Code Playgroud)

jsp*_*ine 3

无需遍历父/子树,只需将 itemcounttext 设置为 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());
});
Run Code Online (Sandbox Code Playgroud)