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

2

14

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);
     }
Embrocation answered 14/5, 2015 at 7:11 Comment(6)
have you tried item.children[1].setText(squantity);Meier
@VRK yes tried .But it's also not working.Embrocation
I see itemcounttext defined, but it's not referenced anywhere else. In this code, it's not a parent or child of anything else defined there. Why not make itemcounttext a property of additem? Then you could additem.itemcounttext.setText(whatever).Corrinacorrine
Are you testing on emulator, simulator or a real device ? I have tried to reproduce your bug but .. it just work fine for me on both simulator and device.Anear
@Anear yes i have testing with all simulator ,emulator and real android device(micromax and sony).but i have facing this issue on these devices.Embrocation
@KrishnaVeni well... Could you expose a full workable example so that we can try to reproduce your bug ? (I mean, please name your snippets with corresponding files, and write down anything that take part to the process).Anear
C
3

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());
});
Corrinacorrine answered 18/5, 2015 at 19:19 Comment(2)
I still don't see itemcounttext as a parent or child of additem in your code. But that's OK. Instead of item.countTextLabel.setText(squantity);, Just do itemcounttext.setText(squantity);. itemcounttext is in the scope of your event listener, doesn't need to be passed to it.Corrinacorrine
it's also tried.not working...itemcounttext is a sibling of a additem.Embrocation
R
0

I struggled with this for the better part of an afternoon. Hopefully this helps someone.

In my case I had a tableview with just 1 custom row by design. Clicking the row allowed me to choose a new value (name and description) from a different tableview, and then update the first tableview custom row data with the newly selected values.

For the problematic tableview, I was using setData, but the custom rows are fairly complex so I didn't want to have to rebuild one row of one of these complex rows. Here is what worked for me... I just updated the labels in the data array that are contained in a wrapper view that is contained in the row. This way rather than rebuilding all of the data array from scratch, I was able to modify the array and then just set data again. dataStatus[0].children[0].children[0].text = sice.row.name;
dataStatus[0].children[0].children[1].text = sice.row.statusdescription; tableviewStatus.setData(dataStatus);

I only have 1 row so dataStatus[0] addresses that row. Then the first child is the wrapper view, and I counted my layout and the 1st and 2nd child of the wrapper are the labels I needed to update. Then after I modified the array, I just redid setData. Worked like a champ.

Hope it helps someone.

Revolting answered 31/3, 2016 at 21:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.