Titanium Community Questions & Answer Archive

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

Titanium.UI.ScrollableView not firing event in view change

How can I capture the the swipe event when I switch between views. The swipe event doesnt not fire all the time in the iphone simulator.

newsScrolView.addEventListener('swipe',function(e){
Titanium.API.info(newsScrolView.currentPage);
});

Even when the swipe event is fired, I get the previous view as the current Page values. Is there a correct way to get this done. I need to get a event fired when I user switches between views. And when the event is fired i need to know the currentPage.

— asked December 6th 2010 by Blessan Mathew
  • titanium.ui.scrollableview
0 Comments

2 Answers

  • Use the scroll event instead of the swipe event.

    — answered December 6th 2010 by James K
    permalink
    4 Comments
    • In the scrollable view each view is a ScrollView. So the event gets fired even when i do a horizontal scrolling. I actually need a way to know the user switched to the next view. I tried the scroll event and it works but I have the problem i mentioned. Isnt there like a viewswitch event or something similar to that?

      — commented December 6th 2010 by Blessan Mathew
    • Use the scroll event and check whether yourScrollableView.currentPage has changed.

      — commented December 7th 2010 by James K
    • When you listen to the scrollableView 'scroll' event. it doesn't update all the time. If you scroll quickly you will notice that it skips pages.

      Here is a sample:

      var win = Titanium.UI.createWindow({  
          backgroundColor:'#fff'
      });
      
      var views_arr = [];
      
      for(var i=0; i<10; i++){
          views_arr[i] = Ti.UI.createView({
              width: 200,
              height: 100,
              borderColor:'#000' 
          });
          var lbl = Titanium.UI.createLabel({
              text:'view '+i,
              color:'#000',
          });
          views_arr[i].add(lbl);
      }
      
      scrollableView = Titanium.UI.createScrollableView(
      {
          views: views_arr,
          top: 0,
          left: 0,
          right: 0,
          borderWidth: 0,
          showPagingControl:true
      });
      
      scrollableView.addEventListener('scroll', function(e)
      {
          Ti.API.info("Image Scrolled current page: " + e.currentPage);
      });
      
      win.add(scrollableView);
      win.open();
      

      When you look at the log you will see, that it skips some views:
      INFO] Image Scrolled current page: 1
      [INFO] Image Scrolled current page: 2
      [INFO] Image Scrolled current page: 6
      [INFO] Image Scrolled current page: 7
      [INFO] Image Scrolled current page: 8

      This is an iPhone specific issue. Android works fine.
      Tested on Ti. 1.6.1 and iPhone 4.2

      — commented March 22nd 2011 by Daniel Tome
    • pageChanged event I wrote like this http://developer.appcelerator.com/question/141415/scrollable-views-scroll-event-behaviour-changes-in-sdk-version-211

      — commented September 10th 2012 by Naga Harish Movva
  • aren't you getting a focus event on the new view when it becomes active/focused?

    — answered December 6th 2010 by Aaron Saunders
    permalink
    3 Comments
    • I could not find any focus event for the scrollableview and the scroll view. Can u explain a bit more?

      — commented December 7th 2010 by Blessan Mathew
    • Does anybody know how to solve this? Or is this some sort of bug? I just need a event that will fire whenever the user switches between views.

      — commented December 8th 2010 by Blessan Mathew
    • pagechanged event I wrote like this pageChange Event on Scrollable view

      — commented September 10th 2012 by Naga Harish Movva
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.