[英]Label text is not updating in tableview children in titanium android.but work's in IOS
我試圖使用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());
這是收到具有正確更新值的警報,但是它沒有顯示在標簽中。 您能給我一個解決Android中此問題的想法嗎?
編輯:
從VRK的評論中我也嘗試過此方法。但是它不起作用,但是正在正確接收警報。
item.children[1].setText(squantity);
編輯:
我嘗試使用jsplaine answer。但是我無法獲得解決方案。 在這里我創建了tableview。在該tableview行中,我們正在創建view。在該視圖中我已經添加了additem,itemcounttext值。如果我們單擊additem意味着需要更改itemcounttext值。這是一個流程。
如下圖所示,是我的應用程序tableview的子視圖:
productname
remove itemcount add
image text image
這三個圖像,文本,圖像值被添加到一個視圖中。這就是為什么在單擊添加圖像時添加用於獲取父視圖的代碼的原因:
var item=e.source.getParent();
在這里獲取父對象。還編寫了以下代碼以獲取該視圖的標簽:
item.children[1].text
如果單擊添加圖像,則正在使用此代碼alert(item.children[1].getText())
驗證的.am正確將得到的標簽值正確alert(item.children[1].getText())
。 但更新后的值未顯示。這是我的確切疑問。
編輯:
這是我的完整源代碼。
dataArray = [];
$.ViewCartItemslist_total_value.text = totalamount;
for( var i=0; i<data.length; i++){
//創建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
}));
//在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);
}
無需遍歷父/子樹,只需將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());
});
我為此苦苦掙扎了一個下午的大部分時間。 希望這對某人有幫助。
就我而言,我的設計只有一個自定義行的表格視圖。 單擊該行允許我從其他表視圖中選擇一個新值(名稱和描述),然后使用新選擇的值更新第一個表視圖自定義行數據。
對於有問題的表視圖,我使用的是setData,但是自定義行相當復雜,因此我不想必須重建這些復雜行之一中的一行。 這是對我有用的...我剛剛更新了數據數組中包含在該行中的包裝器視圖中的標簽。 這樣,我無需從頭開始重建所有數據數組,而是可以修改數組,然后再次設置數據。 dataStatus [0] .children [0] .children [0] .text = sice.row.name;
dataStatus [0] .children [0] .children [1] .text = sice.row.statusdescription; tableviewStatus.setData(dataStatus);
我只有1行,所以dataStatus [0]解決了這一行。 然后第一個孩子是包裝器視圖,我計算了布局,包裝器的第一個和第二個孩子是我需要更新的標簽。 然后,在修改數組之后,我只需重做setData。 像冠軍一樣工作。
希望它可以幫助某人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.