Skip to content

Instantly share code, notes, and snippets.

@aaronksaunders
Created October 16, 2011 07:04
Show Gist options
  • Save aaronksaunders/1290599 to your computer and use it in GitHub Desktop.
Save aaronksaunders/1290599 to your computer and use it in GitHub Desktop.
Handling click event in button/view on a row
var win = Ti.UI.createWindow({});
var tableView = Ti.UI.createTableView({});
for(var i = 0; i < 5; i++) {
var checkBox = Ti.UI.createView({
width : 20,
height : 20,
done : false,
item_type : "CHECKBOX", // us this to know we clicked a checkbox
left : 5,
borderWidth : 10,
borderRadius : 10
});
checkBox.borderColor = 'red';
var tableRow = Ti.UI.createTableViewRow();
// set this so we dont get the blue highlight when selecting the button
tableRow.selectedBackgroundColor = 'transparent';
tableRow.add(checkBox);
tableView.appendRow(tableRow);
}
// put an event listener on the whole row, but look for the checkbox when
// handling the specific event
tableView.addEventListener('click', function(evt) {
Ti.API.debug(JSON.stringify(evt));
// if the item clicked was a check box, then handle it
if(evt.source.item_type === "CHECKBOX") {
if(evt.source.done === true) {
evt.source.done = false;
evt.source.borderColor = 'red';
} else {
evt.source.done = true;
evt.source.borderColor = 'green';
}
} else {
alert("Clicked the row, but not the checkbox");
}
});
win.add(tableView);
win.open();
@TheNiks
Copy link

TheNiks commented Mar 22, 2013

it's very nice code thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment