Created
October 16, 2011 07:04
-
-
Save aaronksaunders/1290599 to your computer and use it in GitHub Desktop.
Handling click event in button/view on a row
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it's very nice code thanks