javascript - 在钛 TableView 行中选择特定元素

标签 javascript android titanium

您好,我正在使用 Titanium 开发 Android 应用程序。我想在点击事件中更改图像。但是我无法在表格 View 中选择特定图像。我使用了以下代码:

var user_table = Ti.UI.createTableView({minRowHeight:5.length,hasChild:true});
var data = [];
for (var i=0;i<5.length;i++)
    {
        var row = Ti.UI.createTableViewRow({height:'auto',className:"row"});
        var username = Ti.UI.createLabel(
        {
            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);
var imageView = Ti.UI.createImageView(
        {
            image:'../images/user.png',
            left:0,
            top:0,
            height:25,
            width:25
        });row.add(imageView);          
    }
    feed_table.setData(data);
    feedWin.add(feed_table); 

我想在表格 View 的特定行中定位图像,以便我可以在单击事件时用另一个图像替换它。帮我选择那个特定的图像

最佳答案

1) 在您的 TableView 中,在整行上设置事件监听器。

tableView.addEventListener('click',function(event){
    if ( event.source.id === undefined ) {
        // if no id defined then you know it is not an image...
    } else {
        // you have an id, you have an image..
        var rowNumber = event.index;
        var image = event.source;
    }
});

2) 当你创建你的图片时,为每个图片设置一个id,这样你就可以在点击事件中识别它

var imageView = Ti.UI.createImageView({
    id :"image_"+ i, // set object id
    image:'../images/user.png',
    left:0,
    top:0,
    height:25,
    width:25
 });

关于javascript - 在钛 TableView 行中选择特定元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7565990/

相关文章:

javascript - 钛加速器 : FileUriExposedException - How to use Content Provider?

javascript - Server-Sent Events 究竟是如何工作的?

适用于 Google Drive 的 Android API?

android - 命令 "ionic cordova emulate android"不起作用

Android 日志与 Titanium INFO

javascript - 对象为空但对象属性不是?

javascript - 在Python和Beautiful Soup Web Scraping中提取Javascript变量对象数据

android 美国语言环境不工作

Titanium:如何在其选项卡中关闭 TabGroup?

javascript - 如何将 "push' 一个新项添加到数组的中间?