Time for action – making something happen when the button is pressed
Perform the following steps to make something happen when the button is pressed:
Add an event listener to the button. This event listener will respond when the user clicks on the button.
button1.addEventListener('click', function(e) {alert('You clicked me!')})
Run the app and click on the button!
What just happened?
You added an event listener to the button so that when the button is clicked, an alert box is displayed. The Appcelerator documentation lists the events that are applicable for an object. You will use event listeners frequently in Titanium. They are explained in more detail in Chapter 4, Gluing Your App Together with Events, Variables, and Callbacks.