Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-1653] Android: Need support for Android long press event

GitHub Issuen/a
TypeNew Feature
Resolution Date2011-07-19T17:03:30.000+0000
Affected Version/sRelease 1.6.2
Fix Version/sSprint 2011-29, Release 1.8.0
ReporterDawson Toth
AssigneeBill Dawson


It's not currently possible to add an event listener for a 'long press' event on Android (pressing and holding the finger on a widget for a second or two), which is very frequently used for things like context menus on Android.

In StatusNet Mobile's accounts list we're trying to use a long-click to trigger a context menu for controls such as deletion to provide a more native-feeling interface (on iPhone we use the TableView's native editing mode, which is iOS-specific).

Since the native event isn't available, for now we're trying to emulate it by listening for touchstart, touchend etc. This seems to interfere with the natural behavior of the tableview rows; here's the entry in our bug tracker for this:


On the Android side, SimpleGestureListener has an onLongPress stub method which could be overridden to fire a 'longpress' event; it looks like long press support might need to be activated on the GestureDetector by calling setIsLongpressEnabled (I'm uncertain what the default value is, but if it's on scroll events don't work, so perhaps it should only be set when a listener is present):

http://developer.android.com/reference/android/view/GestureDetector.SimpleOnGestureListener.html"> http://developer.android.com/reference/android/view/GestureDetector...

http://developer.android.com/reference/android/view/GestureDetector.html"> http://developer.android.com/reference/android/view/GestureDetector...




  1. Zipcar (Goss) 2011-04-15

    What's the status of this?

  2. Dawson Toth 2011-06-10

    Updated priority to match this tickets dependency, [TIMOB-3492]. Both have a decent amount of interest from customers now.
  3. Dawson Toth 2011-06-20

    Sample Code

    The following code is an example of how we could utilize the long press from JavaScript. Drop it in an app.js and long press the label! (Hold down on the label for a couple of seconds, and an alert would be displayed.)
       var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
       var label = Ti.UI.createLabel({
           text:'Long press this label, I dare you.',
       label.addEventListener('longpress', function(evt) {
           alert('PASS: You long pressed the label!');
  4. Bill Dawson 2011-07-07

    Though we can (and will, via this ticket) provide longpress events, isn't the real issue that we should support registering context menus on views? Because for the real native experience you'd want a true Android context menu.
  5. Dawson Toth 2011-07-07

    @Bill: yup; [TIMOB-3492]
  6. Bill Dawson 2011-07-18

    longpress and longclick added. TESTING NOTES: * KitchenSink: Base UI -> Window Events has a longpress test. * KitchenSink: Base UI -> Views -> Table Views -> Basic has longclick events on the tableview rows. * The attached app.js is the test app I used while developing this. It's got a few touch-related events on each of the views/controls that it displays. But it only shows the results via log messages, so you'll have to use logcat to use it.
  7. Bill Dawson 2011-07-18

    The app I used for testing while developing. (see attached app.js)
  8. Don Thorp 2011-07-19

    code review and functional test.
  9. Sindre Sorhus 2011-10-28

    What about long press for iOS?
  10. Don Thorp 2011-10-28

    longpress was added to iOS in TIMOB-4508
  11. Shawn Lipscomb 2012-01-18

    But no longpress event at the TableView level? Please add it.
  12. Michael Pettiford 2012-02-08

    Closing issue Tested with Ti Studio build Ti Mob SDK 1.9.0.v20120207171634 OSX Lion 10.7.3 Nexus S OS 2.3.6 v8/rhino Verified that long press events are implemented and work correctly

JSON Source