[英]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.