更改和保留表视图钛中更改的元素

发布于 2024-12-07 00:41:32 字数 1453 浏览 1 评论 0原文

你好,我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

葮薆情 2024-12-14 00:41:32

我也有同样的问题。最后,我删除了旧图像,并在每次点击事件时用新图像替换它。这很烦人,但我没有找到其他解决方案。钛合金的机器人部分有时会出现很多问题。

[更新]
我修改了旧代码 一点点:

/* creates our imageView with specific url */
createImage = function(url)
{
  var imageView = Ti.UI.createImageView(
  {
    image:url,
    left:0,
    top:0,
    height:25,
    width:25
  });

  return imageView;
};

/* creates our tableview row with imageView */
addRow = function(_args)
{
  var row = Ti.UI.createTableViewRow(
  {
    height:'auto',
    className:"row"
  });

  var username = Ti.UI.createLabel(
  {
    text: _args.text || 'user name',
    height:'auto',
    font:{fontSize:12, fontFamily:'Helvetica Neue', color:'#000'},
    width:'auto',
    color:'#000',
    textAlign:'left',
    top:0,
    left:35,
  });
  row.add(username);

  /* create initial imageview */
  var imageView = createImage(_args.image);
  row.add(imageView);    

  /* custom function to set image */
  row.setImage = function(image_url)
  {
    /* remove the old image */
    row.remove(imageView);    
    imageView = null; 

    /* add new image */
    imageView = createImage(image_url);
    row.add(imageView);   
  };

  row.addEventListener('click',function(e)
  {
    /* on click replace the image */
    row.setImage('new/image/path');
  };

  return row;
}

var user_table = Ti.UI.createTableView({minRowHeight:5.length,hasChild:true});
var data = [];
for (var i=0;i<5.length;i++)
{
  var newRow = addRow({
    text: 'my text',
    image: 'my image url'
  });
  data.push(newRow);
}

feed_table.setData(data);
feedWin.add(feed_table); 

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:

/* creates our imageView with specific url */
createImage = function(url)
{
  var imageView = Ti.UI.createImageView(
  {
    image:url,
    left:0,
    top:0,
    height:25,
    width:25
  });

  return imageView;
};

/* creates our tableview row with imageView */
addRow = function(_args)
{
  var row = Ti.UI.createTableViewRow(
  {
    height:'auto',
    className:"row"
  });

  var username = Ti.UI.createLabel(
  {
    text: _args.text || 'user name',
    height:'auto',
    font:{fontSize:12, fontFamily:'Helvetica Neue', color:'#000'},
    width:'auto',
    color:'#000',
    textAlign:'left',
    top:0,
    left:35,
  });
  row.add(username);

  /* create initial imageview */
  var imageView = createImage(_args.image);
  row.add(imageView);    

  /* custom function to set image */
  row.setImage = function(image_url)
  {
    /* remove the old image */
    row.remove(imageView);    
    imageView = null; 

    /* add new image */
    imageView = createImage(image_url);
    row.add(imageView);   
  };

  row.addEventListener('click',function(e)
  {
    /* on click replace the image */
    row.setImage('new/image/path');
  };

  return row;
}

var user_table = Ti.UI.createTableView({minRowHeight:5.length,hasChild:true});
var data = [];
for (var i=0;i<5.length;i++)
{
  var newRow = addRow({
    text: 'my text',
    image: 'my image url'
  });
  data.push(newRow);
}

feed_table.setData(data);
feedWin.add(feed_table); 
一城柳絮吹成雪 2024-12-14 00:41:32

我更喜欢使用带有背景图像的 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.

遗心遗梦遗幸福 2024-12-14 00:41:32

请删除 TableView 和 TableViewRow 中的 Ti.UI.SIZE 高度和宽度...它将起作用。

Please remove your Ti.UI.SIZE in TableView and TableViewRow both height and width... It will work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文