Stopping event listener of tableviewrow in Titanium
when the user click on the tableviewrow, alert box 'row' will occur. And inside the tableviewrow, it contains another view that contains a image vi开发者_运维问答ew. An alert box 'label' will popout when user click on the image. Now the problem is when user click on the image, not only the alert box 'label' will popup, but the alert box 'row' too. How can I avoid the alert box 'row' from popping out when user click on the image? The alert box 'row' appear when user click on the tableviewrow other than the image. Thanks..
var row = Titanium.UI.createTableViewRow({
className:'rowclass',
});
var u_image = Titanium.UI.createImageView({
image: 'image.jpg',
top:10,
left:4,
height:36,
width:36,
});
row.add(u_image);
RegData.push(row);
u_image.addEventListener('click', function(e){
alert('label');
});
row.addEventListener('click', function(e){
alert('row');
});
Ti 1.6, Android 2.2
create your image view with an id
var u_image = Titanium.UI.createImageView({
image: 'image.jpg',
id: "image_view",
top:10,
left:4,
height:36,
width:36,
});
put your listener on the whole table and not just specific elements
myTable.addEventListener('click', function(e){
if(e.source.id == "image_view") {
alert('image_view');
} else {
alert('row');
}
});
Check to make sure you aren't clicking on the image inside of the row first before alerting.
row.addEventListener('click', function(e){
if(e.source != "[object TiUIImageView]") {
alert('row');
}
});
精彩评论