Skip to content

Instantly share code, notes, and snippets.

@meeech
Created May 15, 2012 22:37
Show Gist options
  • Save meeech/2705664 to your computer and use it in GitHub Desktop.
Save meeech/2705664 to your computer and use it in GitHub Desktop.
Longpress example for Titanium toolbar
var win = Ti.UI.createWindow({
backgroundColor: "#ccc",
fullscreen: true,
modal: true
});
//Create the button. We use backgroundImage so that we get
//the standard effect where the button get grey when tapped
var button = Titanium.UI.createButton({
width: 40,
height: 40,
backgroundImage:'images/plus.png'
});
//Create the container - we apply the event listeners to this view.
//In this example, its just the size of the button itself.
var buttonContainer = Ti.UI.createView({
width: 40,
height: 40
});
buttonContainer.addEventListener('longpress', function(e) {
alert('Longpress!');
});
//We use Singletap instead of click - otherwise, the click will fire when you remove your finger
//under normal circumstances (not when using an alert, but during normal flow it will)
buttonContainer.addEventListener('singletap', function(e) {
alert('Singletap');
});
buttonContainer.add(button);
win.setToolbar([buttonContainer]);
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment