在钛表视图行选择特定元素 [英] select particular element in row of table view in titanium

查看:109
本文介绍了在钛表视图行选择特定元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我开发使用钛Android应用程序。我想改变点击图片event.But我无法在表view.I来选择特定的影像中使用以下code:

hi I am developing Android application using Titanium. I want to change image on click event.But I am unable to select particular image in table view.I used following code:

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); 

我要在目标表视图的特定行形象,这样我可以与click事件另一个图像替换它。帮我选择特定的图片

I want to target image in particular row of table view so that i can replace it with another image on click event. help me for selecting that particular image

推荐答案

1)在你的表视图,集全行的事件监听器。

1) in your table view, set the event listener on the whole row.

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,因此您可以识别它的单击事件

2) when you create your images, set an id on each one so you can identify it in the click event

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

这篇关于在钛表视图行选择特定元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆