[英]Titanium TableView in Android
嗨,我面臨着TableView問題。 我有一個TableView並向TableView添加了5行。 每行有2張圖像。
var tableRow = Ti.UI.createTableViewRow({
className : 'row',
objName : 'row',
height : 'auto',
top : '10dip',
bottom : '10dip',
left : '20dip',
right : '30dip',
height : '80dip'
});
var backgroundView = Ti.UI.createView({
backgroundImage : '/images/list-bg.png',
width : '90%',
height : '75dip'
});
var full= Ti.UI.createImageView({
image : '/images/boxfull.png',
right : 10,
top : 35,
width : 20,
height : 20,
visible : false,
objName: 'checkImage'
});
backgroundView.add(checkImage);
var empty= Ti.UI.createImageView({
image : '/images/boxempty.png',
visible : false,
right : 10,
top : 35,
width : 20,
height : 20,
objName: 'uncheckImage'
});
backgroundView.add(uncheckImage);
var requestName = Ti.UI.createLabel({
text : '' + json.requestName,
left : '60dip',
top : '5dip',
right : '10dip',
textAlign : 'left',
ellipsize : true,
wordWrap : false,
font : {
fontSize : '12dip',
fontWeight : 'bold'
},
color : '#285a8c',
height : '30dip',
});
backgroundView.add(requestName );
tableRow.add(backgroundView);
section1.add(tableRow);
tableView.setData(data);
當用戶單擊按鈕時,這些圖像之一應顯示給用戶。
var sectionArray = tableView.getData();
var sectionsLength = tableView.getData().length;
for (var i = 0; i < sectionsLength ; i++) {
Ti.API.info("get sections-->" + i);
var rows = [];
rows = sectionArray[i].getRows();
for (var j = 0; j < rows.length - 1; j++) {
if (rows[j].requestId != undefined) {
Ti.API.error(JSON.stringify(rows[j].children[0]));
rows[j].children[0].children[1].visible = true;
}
}
}
然后,如果用戶單擊該行,則需要顯示其他圖像,並且上一個圖像應該是不可見的。
if (e.row.children[0].children[1].visible == true) {// if emptyimage visible is true then change visibility to false
e.row.children[0].children[1].visible = false;
// change visibility of checked image to true
e.row.children[0].children[0].visible = true;
} else {
//change checked image visibility to false
e.row.children[0].children[0].visible = false;
// change unchecked image visibility to true
e.row.children[0].children[1].visible = true;
}
一切正常,我能夠加載Table。 但是,當用戶單擊按鈕時,表中的每一行都不會顯示boxempty.png圖像。 當我旋轉屏幕方向或滾動表格視圖時,只有我才能看到boxempty.png圖像。 當用戶單擊表行時,同樣的問題是重復顯示boxfull.png。 我在Android中面臨的這個問題。
只需嘗試將圖像視圖的尺寸更改為每個寬度和高度為25px。 創建多個選擇器選擇器時遇到了相同的問題。 我在那里使用了上述尺寸。 我不知道問題的確切原因。 我在整個應用程序中都使用了像素。
var empty= Ti.UI.createImageView({
image : '/images/boxempty.png',
visible : false,
right : 10,
top : 35,
width : 25,
height : 25,
objName: 'uncheckImage'
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.