Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Android: Do Events (Swipe) Work with Views?

Hello,

On the iPhone KitchenSink app, on the Base UI –> Views screen there is an item called "Events with Views." When I tap that item, I see a screen that records events such as touchstart, singletap, swipe etc.

On the Android KitchenSink app, there is no "Events with Views" item under Base UI –> Views.

I want to use a swipe gesture to scroll between views that are displaying an image along with a couple of buttons. On the Android emulator, when I do a click/hold + mouse move to simulate a swipe, the image moves right or left but no swipe event appears to fire (I have a Ti.API.info in the swipe event handler).

My question: Is the swipe event supported on Android views? If not, is there another way I can swipe to move between images on the view?

Judging from how the "Events with Views" demo is absent from Android KitchenSink, and from my own experience, I'm guessing events aren't working on Android views, but I want to make sure.

Thank you!!!!

-Ryan

— asked October 27th 2010 by Ryan Asleson
  • android
  • view
0 Comments

4 Answers

  • Not sure if this is still relevant but this is how I implemented swipe on Android:

    var x_start;
    my_image_view.addEventListener('touchstart', function (e) {
        x_start = e.x;
    });
    my_image_view.addEventListener('touchend', function (e) {
        if (e.x > x_start) {
            swipe({direction: 'right'});
        } else {
            swipe({direction: 'left'});
        }
    });
    
     // And then my swipe function:
    function swipe(e) {
        if (e.direction == 'left') {
           //...
        } else { 
           //...
        }
    }
    
    — answered April 3rd 2011 by David Bankier
    permalink
    0 Comments
  • Hi Ryan,
    In Android, 'swipe' event did not work for View, it only worked for "ScrollView". Even Iam trying to get that swipe effect on View, currently Iam working on it but I am tyring to use "touchstart" and "touchmove" events to achieve this.

    I can share that code with you once I get it functional.
    -ajay

    — answered November 21st 2010 by Liping Zong
    permalink
    0 Comments
  • Ryan

    This feature is not yet available for android, except for scrollView. Tickets #767, #768, and #1703 are the ones to watch if you want to be kept up to date by email.

    — answered November 21st 2010 by Paul Dowsett
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.