Titanium 单击事件不';单击Tianium ImageView时不工作

Titanium 单击事件不';单击Tianium ImageView时不工作,titanium,titanium-mobile,Titanium,Titanium Mobile,我正在为iphone开发一款移动网络应用程序。我从web服务获取数据的地方。 问题是我的图像视图不适用于单击事件。我不知道原因。。。 请帮忙。。。我把我的密码贴在下面 Titanium.include('commonFile.js'); var win = Ti.UI.currentWindow; var url = carsDetailUrl + nid; var imageArea = Titanium.UI.createView({ w

我正在为iphone开发一款移动网络应用程序。我从web服务获取数据的地方。 问题是我的图像视图不适用于单击事件。我不知道原因。。。 请帮忙。。。我把我的密码贴在下面

    Titanium.include('commonFile.js');

    var win = Ti.UI.currentWindow;

    var url = carsDetailUrl + nid;

    var imageArea = Titanium.UI.createView({
        width : 300,
        top: 50,
        height : 125,
        borderRadius : 6
    });

    var image1 = Ti.UI.createImageView({
            image : "",
            left : '8dp',
            top : '10dp',
            width : 135,
            height : 106,
            touchEnabled : 'true',
            borderColor : '#000000',
            borderRadius : 6,
            borderWidth : 1,
        });
    var completeScrollView = Ti.UI.createScrollView({
                top : '0dp',
                left : '0dp',
                contentWidth : 320,
                touchEnabled : 'true',
                borderRadius : 10,
                backgroundImage : '../images/bg.png',
                showHorizontalScrollIndicator : false,
                showVerticalScrollIndicator : false,
                //height : '300dp'
            });


    var xhr = Ti.Network.createHTTPClient({
        onload : function() {

            var tableData = [];
            var headLines, imageLabel, i, row, viewDetail, cars, images;

            cars = JSON.parse(this.responseText);
            headLines = cars.data[1];
            images = cars.data[1]['image'];

            var mainScrollView = Ti.UI.createScrollView({
                top : '0dp',
                left : '0dp',
                contentWidth : 320,
                touchEnabled : 'true',
                borderRadius : 10,
                backgroundImage : '../images/bg.png',
                showHorizontalScrollIndicator : false,
                showVerticalScrollIndicator : false,
            });

            var viewDetail = Ti.UI.createView({
                top : '10dp',
                left : '10dp',
                height : 'auto',
                width : '94%',
                touchEnabled : 'true',
                borderRadius : 10,
                backgroundColor : '#FFFFFF',
            });

       image1.image = encodeURI(images[1]);

       /*var image1 = Ti.UI.createImageView({
            image : encodeURI(images[1]),
            left : '8dp',
            top : '10dp',
            width : 135,
            height : 106,
            touchEnabled : 'true',
            borderColor : '#000000',
            borderRadius : 6,
            borderWidth : 1,
        });*/

            var image2 = Ti.UI.createImageView({
                image : encodeURI(images[2]),
                left : '150dp',
                top : '11dp',
                width : '70dp',
                height : '50dp',
                borderColor : '#000000',
                borderRadius : 3,
                borderWidth : 1,
            });

            viewDetail.add(imageArea);
            imageArea.add(image1);
            imageArea.add(image2);

            mainScrollView.add(viewDetail);
            mainScrollView.add(view2nd);

            completeScrollView.add(mainScrollView);
            win.add(completeScrollView);

        },

        onerror : function(e) {
            alert('There was an error retrieving the remote data. Please check your internet cunnectivity.');
        },
        timeout : 45000
    });

    xhr.open("GET", url);
    xhr.send();

image1.addEventListener('click', function(evt) {    
            Ti.API.info("image clicked");

                var newWin = Ti.UI.createWindow({
                    url : '../automobileSubClass/carImageGallery.js',
                    title : nTitle,
                    tabBarHidden : true,
                    barColor : '#000000',
                    //navBarHidden : true,
                    backgroundImage : "../images/bg.png"
                });
                Titanium.UI.currentTab.open(newWin, {
                    animated : true
                });

            });

但是如果我创建了一个按钮去那个url,然后按钮点击工作。。。但我需要在用户单击图像时单击工作。。。请帮忙。谢谢..

试试这段代码。我已经设置了视图的高度并删除了Web服务以检查您的点击率。工作正常

//Titanium.include('commonFile.js');

    var win = Ti.UI.currentWindow;
         win.backgroundColor='black';

   // var url = carsDetailUrl + nid;

    var imageArea = Titanium.UI.createView({
        width : 300,
        top: 50,
        backgroundColor:'white',
        height : Ti.UI.SIZE,
        borderRadius : 6
    });

    var image1 = Ti.UI.createImageView({
            image : 'KS_nav_ui.png',
            left : '8dp',
            top : '10dp',
            width : 135,
            height : 106,
            backgroundColor:'blue',
            touchEnabled : 'true',
            borderColor : '#000000',
            borderRadius : 6,
            borderWidth : 1,
        });
    var completeScrollView = Ti.UI.createScrollView({
                top : '0dp',
                left : '0dp',
                contentWidth : 320,
                touchEnabled : 'true',
                borderRadius : 10, 
               // backgroundImage : '../images/bg.png',
                showHorizontalScrollIndicator : false,
                showVerticalScrollIndicator : false,
                height : Ti.UI.SIZE
            });



            var mainScrollView = Ti.UI.createScrollView({
                top : '0dp',
                left : '0dp',
                contentWidth : 320,
                touchEnabled : 'true',
                borderRadius : 10,
                backgroundColor:'yellow',
               // backgroundImage : '../images/bg.png',
                showHorizontalScrollIndicator : false,
                showVerticalScrollIndicator : false,
            });

            var viewDetail = Ti.UI.createView({
                top : '10dp',
                left : '10dp',
                height : 'auto',
                width : '94%',
                touchEnabled : 'true',
                borderRadius : 10,
                backgroundColor : '#FFFFFF',
            });



       /*var image1 = Ti.UI.createImageView({
            image : encodeURI(images[1]),
            left : '8dp',
            top : '10dp',
            width : 135,
            height : 106,
            touchEnabled : 'true',
            borderColor : '#000000',
            borderRadius : 6,
            borderWidth : 1,
        });*/

            var image2 = Ti.UI.createImageView({
                image :'KS_nav_views.png',
                left : '150dp',
                top : '11dp',
                width : '70dp',
                height : '50dp',
                backgroundColor:'green',
                borderColor : '#000000',
                borderRadius : 3,
                borderWidth : 1,
            });

            viewDetail.add(imageArea);
            imageArea.add(image1);
            imageArea.add(image2);

            mainScrollView.add(viewDetail);
           // mainScrollView.add(view2nd);

            completeScrollView.add(mainScrollView);
            win.add(completeScrollView);




image1.addEventListener('click', function(evt) {    
            Ti.API.info("image clicked");

                var newWin = Ti.UI.createWindow({
                    url : 'newWindow.js',
                    title : 'New Window',
                    tabBarHidden : true,
                    barColor : '#000000',
                    navBarHidden : true,
                   // backgroundImage : "../images/bg.png"
                });
                Titanium.UI.currentTab.open(newWin, {
                    animated : true
                });

请减少代码量。我在您的代码中找不到单击侦听器。@VVoo您好,代码已编辑。。。单击listener就在ajax完成之后…设置视图的高度:Ti.UI.SIZE。给背景颜色检查你的视图是否重叠。我正在检查,因为你提到@adnan,我应该在检查完成后通知你…@adnan非常感谢你。。。这主要是一个视图重叠问题。我解决了它。。你的提示帮助我找到解决办法。如果你发布一个答案,那么我肯定会接受。。再次感谢。