0

다음과 같이 일부 이미지 뷰를 생성합니다.클릭 이벤트를 수신 대기하는 방법 appcelerator의 이미지보기 그룹

// Time buttons 
    var timeButtons =[ 
     { title: 'Afternoon', path: 'images/others/time/afternoon.png'}, 
     { title: 'CurrentTime', path: 'images/others/time/currenttime.png'}, 
     { title: 'Evening', path: 'images/others/time/evening.png'} 
    ] 


createButtons(timeButtons); 


/* Button creation function */ 
function createButtons(data){ 

    for (var i = 0; i < data.length; i++){ 
     //Creating each button 
     var button = Titanium.UI.createImageView({ 
      image: data[i].path, 
      height: 90, 
      width: 90, 
      top: 20+90*i+20*i, 
      value: 1 
     }); 

     //Adding the buttons to the center view 
     centerButtons.add(button); 
    } 
} 

사용자가 imageView 중 하나를 클릭하면 클릭 한 이미지 뷰를 식별하고 이에 따라 작업을 수행합니다.

답변

1
centerButtons.addEventListener('click', function(evt) { 
    alert(evt.source.image); 
}); 
2

추가적으로 매개 변수를 imageView에 추가 할 수 있습니다. 이드처럼. 여기 추가 매개 변수와 함께 예 :

centerButtons.addEventListener('click', function(event) 
{ 
    // Perhaps you should check here if the custom parameter (_id) exist. 

    switch(event.source._id){ 
     case 0: 
      // Your stuff with you first image 
      break; 
     // etc. 
    } 
}); 
: 당신이 당신의 이미지 뷰를 식별하기 위해 새로운 매개 변수를 사용하여보다

for (var i = 0; i < data.length; i++){ 
    //Creating each button 
    var button = Titanium.UI.createImageView({ 
     _id: i, // Your custom parameter 
     image: data[i].path, 
     height: 90, 
     width: 90, 
     top: 20+90*i+20*i, 
     value: 1 
    }); 

    //Adding the buttons to the center view 
    centerButtons.add(button); 
}