更改和保留表视图钛中更改的元素
你好,我正在使用 Titanium 开发 Android 应用程序。为了在单击时更改图像,我使用了以下代码。但问题是,当我单击图像时,它只会更改一次(第一次单击时),当我再次单击时,它不会显示更改后的图像。但在警报中它显示图像源已更改。 (更改没有反映在屏幕上!!?)另一个问题是当我单击(图像发生更改)时,然后进入子窗口并返回。它不保留更改。
var feed_table = Ti.UI.createTableView({minRowHeight:5,hasChild:true});
var data = [];
for (var i=0;i<5;i++)
{
var row = Ti.UI.createTableViewRow({height:'auto',className:"row"});
var username = Ti.UI.createLabel(
{
text:'nilkash',
height:'auto',
font:{fontSize:12, fontFamily:'Helvetica Neue'},
width:'auto',
color:'#000',
textAlign:'left',
top:0,
left:35,
});row.add(username);
var doneCheckbox = Titanium.UI.createImageView(
{
id:'image_'+i,
clickName:'ClickName',
image:'../images/finished-work.png',
width:15,
height:15,
top:32,
left:0,
});row.add(doneCheckbox)
data.push(row);
}
feed_table.setData(data);
feedWin.add(feed_table);
feed_table.addEventListener('click',function(e)
{
if (e.source.clickName == 'ClickName' )
{
if(feed_table.data[0].rows[e.index].children[1].image == '../images/work.png')
{
feed_table.data[0].rows[e.index].children[1].image = '../images/finished-work.png';
}
else if (e.source.clickName == 'ClickName' )
{
feed_table.data[0].rows[e.index].children[1].image = '../images/work.png';
}
}
});
我还使用了另一个简单的解决方案,只是切换两个图像。但它也没有保留这些更改。是否需要再次将更改推送到表视图中?提前感谢您的帮助。
Hi, I am developing an Android application using Titanium. For changing image on click I used following code. But the problem is that when I click on image it will change only once (on first click), when I click again it won't show changed image. But in alert it shows the image source is changed. (The changes are not reflecting on screen!!??) Another problem is when I click (the image gets changed), then go on child window and come back. It is not retaining the changes.
var feed_table = Ti.UI.createTableView({minRowHeight:5,hasChild:true});
var data = [];
for (var i=0;i<5;i++)
{
var row = Ti.UI.createTableViewRow({height:'auto',className:"row"});
var username = Ti.UI.createLabel(
{
text:'nilkash',
height:'auto',
font:{fontSize:12, fontFamily:'Helvetica Neue'},
width:'auto',
color:'#000',
textAlign:'left',
top:0,
left:35,
});row.add(username);
var doneCheckbox = Titanium.UI.createImageView(
{
id:'image_'+i,
clickName:'ClickName',
image:'../images/finished-work.png',
width:15,
height:15,
top:32,
left:0,
});row.add(doneCheckbox)
data.push(row);
}
feed_table.setData(data);
feedWin.add(feed_table);
feed_table.addEventListener('click',function(e)
{
if (e.source.clickName == 'ClickName' )
{
if(feed_table.data[0].rows[e.index].children[1].image == '../images/work.png')
{
feed_table.data[0].rows[e.index].children[1].image = '../images/finished-work.png';
}
else if (e.source.clickName == 'ClickName' )
{
feed_table.data[0].rows[e.index].children[1].image = '../images/work.png';
}
}
});
I also used another simple solution just toggling two images.But it also not retaining these changes. Whether it required to again push that changes in to table view? Thanks for help in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我也有同样的问题。最后,我删除了旧图像,并在每次点击事件时用新图像替换它。这很烦人,但我没有找到其他解决方案。钛合金的机器人部分有时会出现很多问题。
[更新]
我修改了旧代码 一点点:
I had the same problem. In the end I removed the old image and replaced it with a new one on every click event. That's annoying but I found no other solution. The android part of titanium is quite buggy sometimes.
[update]
i modified the old code a little bit:
我更喜欢使用带有背景图像的 createView,它工作得很好。我用它来模拟
CheckBoxes
并且没有任何问题。I prefer to use use a createView with a background image, it works fine. I use it to simulate
CheckBoxes
and I have no problems.请删除 TableView 和 TableViewRow 中的 Ti.UI.SIZE 高度和宽度...它将起作用。
Please remove your Ti.UI.SIZE in TableView and TableViewRow both height and width... It will work.