[英]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. 我试图使用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());
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.
您能给我一个解决Android中此问题的想法吗?
EDIT: 编辑:
From VRK comment i have tried this also.But it's not working.but am getting the alert correctly. 从VRK的评论中我也尝试过此方法。但是它不起作用,但是正在正确接收警报。
item.children[1].setText(squantity);
EDIT: 编辑:
I tried with jsplaine answer.But i can't get the solution. 我尝试使用jsplaine answer。但是我无法获得解决方案。 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.
在这里我创建了tableview。在该tableview行中,我们正在创建view。在该视图中我已经添加了additem,itemcounttext值。如果我们单击additem意味着需要更改itemcounttext值。这是一个流程。
like below screenshot is children view of my app tableview: 如下图所示,是我的应用程序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())
;. 如果单击添加图像,则正在使用此代码
alert(item.children[1].getText())
验证的.am正确将得到的标签值正确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 //创建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 //在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 the parent/child tree, just make itemcounttext a property of additem: 无需遍历父/子树,只需将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());
});
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. 对于有问题的表视图,我使用的是setData,但是自定义行相当复杂,因此我不想必须重建这些复杂行之一中的一行。 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 [0] .text = sice.row.name;
dataStatus[0].children[0].children[1].text = sice.row.statusdescription; dataStatus [0] .children [0] .children [1] .text = sice.row.statusdescription; tableviewStatus.setData(dataStatus);
tableviewStatus.setData(dataStatus);
I only have 1 row so dataStatus[0] addresses that row. 我只有1行,所以dataStatus [0]解决了这一行。 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.
然后,在修改数组之后,我只需重做setData。 Worked like a champ.
像冠军一样工作。
Hope it helps someone. 希望它可以帮助某人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.